Batch rename, changing length of filename

  • Thread starter Thread starter Scott Falkner
  • Start date Start date
S

Scott Falkner

Is there a was to batch rename files, changing the length
of the filename?

I have a lousy scanner that can scan a lot of pictures in
one go. The scans are
named "scan0001.tif", "scan0002.tif", etc. This is
uncongifurable (yes, the software for the lousy scanner is
lousy). I would like to rename the
files "01.tif", "02.tif", etc. I know I can enter DOS and
rename the file with a RENAME" command, but I can't seem
to change the length of the filename.
 
My solution is not generalized but it will remove two zeros following "scan"
in the filenames in a given directory. I think that solves this specific
problem. And it does it using only tools that ship with the OS.

At the cmdline:
dir /b /a-d >oldnames.txt
for /f %i in ('type oldnames.txt') do echo move %i x%i >>changem.bat
Then open changem.bat with Notepad, replace-all "xscan00" with "scan", and
save.
Run changem.bat.

And you can get rid of oldnames.txt and changem.bat when you're done, of
course.
 
Scott said:
Is there a was to batch rename files, changing the length
of the filename?

I have a lousy scanner that can scan a lot of pictures in
one go. The scans are
named "scan0001.tif", "scan0002.tif", etc. This is
uncongifurable (yes, the software for the lousy scanner is
lousy). I would like to rename the
files "01.tif", "02.tif", etc. I know I can enter DOS and
rename the file with a RENAME" command, but I can't seem
to change the length of the filename.

From the CMD prompt (assuming ENABLEDELAYEDEXPANSION is in effect):

for %a in (c:\yourdir\scan*.tif) do (set old=%~nxa&echo ren c:\yourdir\!old! !old:~6!)

If the preceding appears to do what you intend, remove the word 'echo'
to actually rename the files.

If you use the preceding in a batch file, change all '%' to '%%'. For
information about 'ENABLEDELAYEDEXPANSION', type 'CMD /?' (without
the apostrophes) at a CMD prompt.
 
Back
Top