1.

Solve : Renaming Files?

Answer»

Hi,

I am NEW to DOS programming and have another renaming question. I realize that there are a lot of renaming posts out there, but I have not found one which addresses my issue.

I basically need to rename all files in a folder by pre-pending them with the folder name, i.e. C:\Test\File.tif becomes C:\Test\Test-File.tif.

I have come up with the following CODE and it comes close to working

for %%a in ("%CD%") DO SET CurrentFolder=%%~na

for %%B in (*.tif) do rename %%B %currentFolder%-%%B

Run against the following files I get the following results:

C:\CSCAN\FILE1.TIF becomes C:\CSCAN\CSCAN-CSCAN-FILE1.TIF
C:\CSCAN\FILE2.TIF becomes C:\CSCAN\CSCAN-FILE2.TIF
C:\CSCAN\FILE3.TIF becomes C:\CSCAN\CSCAN-FILE3.TIF

Does anybody have an explanation for what is GOING on here?

Thanks in advance.

Bob


Somehow the first file has the directory added twice, I think that the first rename 'moves' the file so that it is PICKED up a second time.

I suggest you use your loop to output the directory list into a file then process the file, that will guarantee that it is not SEEN twice by the loop.

GrahamTook your advice and used a temporary file. Worked like a charm. Thanks for your help.

rwdIt's funny that I stumbled across this.

Just recently I have the exact same need. Could you post your solution?



Discussion

No Comment Found