My Windows 10 Music folder has some albums where there are both MP3 and Flac versions of the songs. There are other albums that only contain MP3’s and still others that contain only Flac’s. In the album folders that both types, I want to delete the MP3’s since they are unnecessary lower quality duplicate versions. I found a script here that was doing something similar but with photos (bmps and jpegs) but it only looked in the photos folder. I have modified it to handle MP3’s and Flac’s, but I can’t figure out how to add recurse to get it to look into each album folder under the Music folder. Can someone help with this?<\/p>\n
Here is the script I am trying to add recurse to:<\/p>\n
$Path = “f:\\music”
\nForEach ($File in (Get-ChildItem $Path *.mp3))
\n{ If (-not (Test-Path “$Path$($File.Basename).flac”))
\n{ $File | Remove-Item -WhatIf
\n}
\n}<\/p>","upvoteCount":3,"answerCount":6,"datePublished":"2021-06-16T17:18:10.000Z","author":{"@type":"Person","name":"spiceuser-nenes","url":"https://community.spiceworks.com/u/spiceuser-nenes"},"suggestedAnswer":[{"@type":"Answer","text":"
My Windows 10 Music folder has some albums where there are both MP3 and Flac versions of the songs. There are other albums that only contain MP3’s and still others that contain only Flac’s. In the album folders that both types, I want to delete the MP3’s since they are unnecessary lower quality duplicate versions. I found a script here that was doing something similar but with photos (bmps and jpegs) but it only looked in the photos folder. I have modified it to handle MP3’s and Flac’s, but I can’t figure out how to add recurse to get it to look into each album folder under the Music folder. Can someone help with this?<\/p>\n
Here is the script I am trying to add recurse to:<\/p>\n
$Path = “f:\\music”
\nForEach ($File in (Get-ChildItem $Path *.mp3))
\n{ If (-not (Test-Path “$Path$($File.Basename).flac”))
\n{ $File | Remove-Item -WhatIf
\n}
\n}<\/p>","upvoteCount":3,"datePublished":"2021-06-16T17:18:11.000Z","url":"https://community.spiceworks.com/t/how-to-modify-this-script-to-recurse-subdirectories/802992/1","author":{"@type":"Person","name":"spiceuser-nenes","url":"https://community.spiceworks.com/u/spiceuser-nenes"}},{"@type":"Answer","text":"
Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n