Saturday, January 25, 2014

Sort\Move files based on first letter

#
# Sort Files based on first letter
#
#
$path='P:\vid\Movies'
# Issue : anything starting with "the" can cause the Q-Z to fill up
# comment out if not required
$thefiles=Get-ChildItem $path -af the*.* -recurse -exclude *.txt,*.jpg,*.nfo
foreach($file in $thefiles){
ren $file ($file.Name).Substring(4)
}
#
#
#
Get-ChildItem $path -af -recurse -exclude *.txt,*.jpg,*.nfo,*.xml | Where-Object {$_.Name -match "^[a-e]"} | ForEach-Object {move $_.fullname P:\sorted\A-E}
Get-ChildItem $path -af -recurse -exclude *.txt,*.jpg,*.nfo,*.xml | Where-Object {$_.Name -match "^[f-k]"} | ForEach-Object {move $_.fullname P:\sorted\F-K}
Get-ChildItem $path -af -recurse -exclude *.txt,*.jpg,*.nfo,*.xml | Where-Object {$_.Name -match "^[l-p]"} | ForEach-Object {move $_.fullname P:\sorted\L-P}
Get-ChildItem $path -af -recurse -exclude *.txt,*.jpg,*.nfo,*.xml | Where-Object {$_.Name -match "^[Q-Z]"} | ForEach-Object {move $_.fullname P:\sorted\Q-Z}

No comments: