Page 1 of 1

renaming extensions on files with underscores

Posted: 05 May 2013 13:53
by mayoko
Hi, normally I never run into issues like this, but recently I came across some file extensions that I want to rename that include underscores, this is really irritating as the usual command I use in my batch files doesn't even print an error.

Example File:

AS_Barrel01.AG

I want to rename it to:

AS_Barrel01.back

I want this to be done to the entire directory and sub-directories if they exist.

Here's what I usually use: cd /d "C:\Folder" for /f "tokens=* delims= " %%a in ('dir /b /ad /s') do rename "%%a\*.AG" "*.back"
As I mentioned this is completely ineffective with these particular files. I tried variants like *_*.AG but it didn't work, I guess it isn't that simple. :(

Re: renaming extensions on files with underscores

Posted: 05 May 2013 14:42
by Endoro
this works here:

Code: Select all

ren *_*.ag *.back

Re: renaming extensions on files with underscores

Posted: 05 May 2013 15:22
by abc0502
Your code is right but you made a big mistake, you told the DIR command to process Directories not Files
for /f "tokens=* delims= " %%a in ('dir /b /ad /s') do rename "%%a\*.AG" "*.back"


But For More Simple Code & As Endoro Said, try this

Code: Select all

@Echo OFF
For /F "delims=" %%A In (' DIR /B /S /A:-D "*_*.ag" ') Do REN "%%A" "%%~nA.back"
pause
This will just rename files that has "_" underscore sign and is a .ag files

Put This Batch in The Main Folder

Re: renaming extensions on files with underscores

Posted: 05 May 2013 15:43
by mayoko
Thanks guys, I'm a little better off than a novice with command prompt, I didn't really understand the flags for that command as I couldn't look it up, it was one of the few cases I just copy and pasted from the internet, lol. :oops: