batchRenaming files in Folder tree

April 13, 2009 at 06:24:01
Specs: Windows XP
Hi,
I want to rename the files in folder tree.
ex: C:\test there are many folder in test folder.
I want to parse each folder and rename the files accordingly.
i.e. rename *.doc to *.txt in very folder under Test folder.

Please let me know the batch file for parsing and renaming the same.


See More: batchRenaming files in Folder tree

Report •


#1
April 13, 2009 at 10:22:09
@echo off & setLocal EnableDelayedExpansion

pushd C:\test

for /f "tokens=* delims=" %%a in ('dir/s/b/a-d *.doc') do (
ren %%a %%~Na.txt
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
April 14, 2009 at 23:30:40
sorry the above batch file is not working... rather it is changing the name of the file and extention is remaining the same.

C:\Test

C:\Test\Newfolder\*.doc to *.txt
C:\Test\Newfolder1\*.doc to *.txt
C:\Test\Newfolder2\*.doc to *.txt
C:\Test\Newfolder3\*.doc to *.txt
C:\Test\Newfolder\abc\*.doc to *.txt
C:\Test\Newfolder\abc\bcd\def\*.doc to *.txt

Like wise i want to change the extention only... not the name of the file...

Please help me out..

thanks,


Report •

#3
April 14, 2009 at 23:41:33
Also getting the syntax of the command is incorrect.
I don't know anything about scripting.

Report •

Related Solutions

#4
April 15, 2009 at 01:00:00
I don't see how it's not working. I edited it to a 'real' dir and refixed the REN with ECHO and here's the output::

ren C:\files\JAMES-BC.doc JAMES-BC.txt


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
April 15, 2009 at 04:49:04
Also getting the syntax of the command is incorrect.
I don't know anything about scripting.

It might be possible that there is space in the folder name and space in .doc file name
e.g. C:\test\New Folder\ New Folder.doc

while renaming individual file with ""
e.g. ren "C:\test\New Folder\ New Folder.doc" "C:\test\New Folder\ New Folder.txt" it is working fine.

So just want to know how the double couts need to be specified in the above script.

thanks,


Report •

#6
April 15, 2009 at 04:50:44
Here is output when the echo is on, on the command prompt.
Please suggest.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (15).doc New Folder (15).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (4).doc New Folder (4).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (5).doc New Folder (5).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (6).doc New Folder (6).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (7).doc New Folder (7).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (8).doc New Folder (8).tmb )
The syntax of the command is incorrect.

C:\Test>(ren C:\Test\New Folder (4)\New Folder (9).doc New Folder (9).tmb )
The syntax of the command is incorrect.


Report •

#7
April 15, 2009 at 05:14:32
@echo off & setLocal EnableDelayedExpansion

pushd C:\test

for /f "tokens=* delims=" %%a in ('dir/s/b/a-d *.doc') do (
ren "%%a" "%%~Na.txt"
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#8
April 15, 2009 at 05:44:20
Yes it is working fine. Thanks a log.

Report •


Ask Question