Yeah that should work, with a few changes:
for /f "usebackq tokens=*" %%g in (`dir /b /s /A:d`) do @cd "%%g" && @ren *.extn1 *.extn2
But in my original reply to the original post by pink_zippy_123, I stated that this would not work as expected on filenames containing multiple "
." in it.
Unfortunately, I got in to teaching mode and went off on a tangent.
After having reread the original post, I think that the ultimate answer to the problem may be something like this for the command line:
for /f "usebackq tokens=*" %h in (`dir /b /A:-D`) do @ren *.extn1 *.extn2 >nul || echo Failure: %h -^> .tql && echo Success: %h -^> .tql) && for /f "usebackq tokens=*" %g in (`dir /b /s /A:D`) do (for /f "usebackq tokens=*" %h in (`dir /b /s /A:-D`) do @ren *.extn1 *.extn2 >nul || echo Failure: %h -^> .tql && echo Success: %h -^> .tql)
Or like this in a batch file:
for /f "usebackq tokens=*" %h in (`dir /b /s /A:-D`) do (
@ren *.extn1 *.extn2 >nul || echo Failure: %h -^> .tql && echo Success: %h -^> .tql
)
for /f "usebackq tokens=*" %%g in (`dir /b /s /A:D`) do (
for /f "usebackq tokens=*" %%h in (`dir /b /s /A:-D`) do (
@ren *.extn1 *.extn2 >nul || echo Failure: %%h -^> .tql && echo Success: %%h -^> .tql
)
) This of course, would traverse all the directories and subdirectories (the second
for statement), renaming all files (represented as
%%h for the batch file and
%h on the command line version) in each of the directories and subdirectories as it goes along (the third
for statement).
The first
for statement is to get all the files in the current directory because the second
for loop will completely miss them; I have not tried this code though, so I invite attempts with results posted to the thread, of course.
P.S. I thnk the batch file (cmd script) method wil be preferable as it makes the code more readable not to metion that I don't think most people will be able to type all that onto the command line without mistyping something. Just look at me; I carefully replied to the post early on and I still missed something (thanx DenisOxon).