powershell - Script to move folders with specific names and characters -
i looking write script move existing folders "-" hyphen in name parent folder part of same name.
example:
i move c:\12345-01 c:\12345\ c:\12345\12345-01.
the problem number of characters before hyphen not same, 3-6 characters before hyphen. have found couple of snipets here , elsewhere close, won't work specify number of characters in file name
for each objfile in objfolder.files strname = left(objfile.name, 3)
this work if filenames 3 characters.
does makes sense?
cd 'c:\directory\of\folder\where\number\files\located' gci | ? {$_.psiscontainer -eq $true} | % { ` $file = $_.name $loc = $file.indexof('-') $folder = $file.substring(0,$loc) new-item -path . -itemtype directory -name $folder -erroraction silentlycontinue move-item $file $folder }
Comments
Post a Comment