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.
- Get Items from $HOME\Music
- Filter down to only ones where PSIsContainer equals True, which returns only folders
- If the number of items in the folder is less than or equal to three…
- …get a list of all files in the directory
- Move all of those items into $Home\Music\Misc
Pretty amazing what one line of PowerShell can do.