One Inch of Power: Bulk file relocation

Hi guys,

Back for another installment of One inch of Power. In this episode, I became sick of seeing my music folder full of folders for albums, each of which may only have a single file or two.

I wrote this one incher to grab all folders with less than three files and move them all into a single folder, for ease of sorting.

"$HOME\Music" | gci | ? PSIsContainer -eq $true | % {
   if ((gci $_.FullName -recurse).Count -le 3){
      gci $_ -recurse *.mp3 | move-item -Destination $HOME\Music\misc 

Here’s the overall flow.
1. Get Items from $HOME\Music
2. Filter down to only ones where PSIsContainer equals True, which returns only folders
3. If the number of items in the folder is less than or equal to three…
4. …get a list of all files in the directory
5. Move all of those items into $Home\Music\Misc

Pretty amazing what one line of PowerShell can do.

Have a code issue? Share your code by going to and pasting your code there, then post the link here!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.