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.
renaming extensions on files with underscores
Moderator: DosItHelp
Re: renaming extensions on files with underscores
this works here:
Code: Select all
ren *_*.ag *.back
Re: renaming extensions on files with underscores
Your code is right but you made a big mistake, you told the DIR command to process Directories not Files
But For More Simple Code & As Endoro Said, try thisThis will just rename files that has "_" underscore sign and is a .ag files
Put This Batch in The Main Folder
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
Put This Batch in The Main Folder
Re: renaming extensions on files with underscores
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.