Rename files using a list #
C:\temp>dir /b
89-bar.htm
a.htm
foo42.htm
C:\temp>type ..\list.txt
foo42.htm 001.htm
89-bar.htm 002.htm
a.htm 003.htm
C:\temp>for /f "tokens=1,2 delims= " %a in (..\list.txt) do ren %a %b
C:\temp>ren foo42.htm 001.htm
C:\temp>ren 89-bar.htm 002.htm
C:\temp>ren a.htm 003.htm
C:\temp>dir /b
001.htm
002.htm
003.htm
- If you save the for loop as a batch file, be sure to use double percent signs (e.g., %%a instead of %a).
- In this example, filenames contained no spaces, so delims was set to space. This could be changed to comma, bar, etc.
- For a dry run, prepend echo to ren %a %b.
- Be sure list.txt has DOS/Windows line endings (CR+LF)
- See also:
/windows | Sep 22, 2011
Subscribe or visit the archives.