I'm going through a large number of folders and files on my personal computer and trying to clean them up. I have a list of folders like this:
- Pictures of ABC
- Pictures of DEF
- Pictures of GHI With JKL
- MNO
- PQR
- ...
I would like to rename some of the folders to remove the leading characters of only those that start with "Pictures of" (or other strings as I find them). I have tried both ren
and move
commands in cmd.exe
with no luck. The following is what I have tried:
ren "Pictures of"* *
ren "Pictures of*" " *"
ren "Pictures of*" "*"
move "Pictures of*" "*"
move "Pictures of"* *
move "Picutres of*" *
Thoughts?
Answer
This is very easy to do in Windows PowerShell, so if you do not insist on using that outdated and outmoded Command Prompt, open PowerShell, navigate to the appropriate folder and issue the following commands:
Get-Childitem -Directory | ForEach-Object {
$a=$_.Name
$b=$a -replace "^Pictures of",""
If ($a -ne $b) { Rename-Item $a $b }
}
I've tested this script in Windows PowerShell 5.1.
No comments:
Post a Comment