Join 3,424 readers in helping fund MetaFilter (Hide)


Batch renaming through sub-directories!
July 22, 2011 10:13 AM   Subscribe

I want to write a batch file that will let me change the extensions of all the files of a certain type (so, like, "ren *.nco *.zip") through all of the sub-directories in a directory. If this is possible, how is it done?

I've been doing this whole thing via the command prompt, and I'm just getting really sick of typing my way through all these sub-directories. Plus, it's taking up far too much of my time.

There's got to be a better way!
posted by The Great Big Mulp to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
Is there any reason you need to do this through a batch file? There are probably freeware apps that will do what you need, like this one (which I haven't used).
posted by burnmp3s at 10:26 AM on July 22, 2011


Look at the for /R command. It should do what you want.
posted by zsazsa at 10:30 AM on July 22, 2011


I have used the renamer burnmp3s links to and it is pretty awesome. I would recommend it if you do even a moderate amount of renaming.
posted by anaelith at 10:51 AM on July 22, 2011 [1 favorite]


I know it's not batch, but powershell can do this in one moderately complicated line:

PS C:\targetdirectory\>Get-ChildItem -Recurse -Filter "*.jpg" | ForEach {Rename-Item $_ -NewName ($_.Basename + ".png")}

If you have Vista or Win7 powershell is probably installed on your system already. Just hit Windows-R, type "powershell", and the powershell window should come up.
posted by benzenedream at 11:13 AM on July 22, 2011


If you're doing it in a CMD window in Windows, up to Win7, it can be done in one command line:

for /f %D in ('dir /b /s') do if %~xD==.txt move %D %~dD%~pD%~nD.ext

Alternately, but a little more processor intensive:

for /f %D in ('dir /b /s *.txt') do move %D %~dD%~pD%~nD.ext

(If you're putting this in a batch file, remember to double-up your % signs)
posted by AzraelBrown at 11:16 AM on July 22, 2011 [1 favorite]


Huzzah! Thanks, all! You've saved my wrists and tendons!
posted by The Great Big Mulp at 11:46 AM on July 22, 2011


I did this with Automator once on my Mac.
posted by squasher at 5:09 PM on July 22, 2011


« Older UK Student Visa (Tier 4) appli...   |  What protection does a non-pro... Newer »
This thread is closed to new comments.