move .mp3 files

by bryanleesterk at 2013-02-15 15:08:07

I am looking to create a ps script to move any folder that contains .mp3 files to a new directory but keeping the mp3 in its original folder. Basically I wan’t power shell to search "J:\Finished Torrents" and if any folders in that directory contain a .mp3 file I would like to move that whole folder to "J:\Music" any help would be appreciated.
by Kottees at 2013-02-16 01:20:45
Hi, Paste the below scripts in a notepad and save it as .ps1 file.

get-childitem -path . -recurse -include *.mp3 | move-item -destination C:\music -force
by bryanleesterk at 2013-02-17 10:39:59
The script you provided actually did nothing. I changed it to

$sourcePath = ‘j:\Finished Torrents’
$destinationPath = ‘J:\Music’
get-childitem -path $sourcePath -recurse -include *.mp3 | move-item -destination $destinationPath -force

and that does move the .mp3’s but not the containing folders like i had asked. Thank you for the suggestion though.
by AlexBrassington at 2013-02-18 00:12:51
I’m not that intersted in the mp3 aspect but the actual goal is an interesting one.

$destinationRootDirectory = 'D:\Files'
$filterTerm

$folders = Get-childItem -Path $sourceRootDirectory -Recurse -Filter $filterTerm | select directory -Unique

That will get unique folders that you can then move. Of course there’s a good chance it won’t work as you want it to, I haven’t tested nested folders.
by bryanleesterk at 2013-02-19 13:58:22
Does absolutely nothing!
by AlexBrassington at 2013-02-19 23:26:06
Absolutely nothing eh, what did you try running?
by bryanleesterk at 2013-03-07 13:56:50
$destinationRootDirectory = 'J:\Finished Torrents'
$filterTerm
$folders = Get-childItem -Path $sourceRootDirectory -Recurse -Filter $filterTerm | select directory -Unique
by AlexBrassington at 2013-03-08 00:10:20
Yes. That won’t move anything. It’s not supposed to.

That will, if you were to specify a filter term and a sourceRootDirectory, identify all the folders that have items in them that match the filter.

You can then copy or move the folders using another line or two of code.