
Where the bat file off&echo This will rename all files containing '_fixed'. ~~ Recurse thru sub-directories, renaming files ~~ ~~ Rename all jpg files in a folder tree (to cover.jpg): ~~ /R c:\ %%f in (*.jpg) do echo rename "%%~ff" cover.jpg ~~ Recurse through all sub-directories (excluding current), changing extension: ~~ offįor /f "tokens=1 delims=" %%a in ('dir /s /b /ad') do if exist "%%a\*.asp" echo ren "%%a\*.asp" *.html > rename.cmd ~~ Rename to random number: ~~ off&setlocalįor /f "tokens=*" %%a in ('dir /b /a:-d "%FileMask%"') do call :process "%%a" ~~ Add a prefix to numbers-only file-name: ~~ įor /f %%a in ('dir /b *.txt ^| findstr /I /X /R /C:^*.txt') do ren %%a prefix%%aįor /f %%a in ('dir /b *.txt ^| findstr /I /X /R /C:^.t xt') do ren %%a pyxbl%%a ::Cuts off 1st 4 characters of fname, then appends prefix callrs*** offįor %%i in (SF03*.CSV) do (set fname=%%i) & call :rename *** ":~4%" crop feature: where is it documented? Please let me know.

(SFyymmddhhmm.csv->SISCR12 mmddhhmm.c sv ) ~~ "REN *.TXT S1-*.TXT" will result in the file TEST1.TXT being renamed to S1-T1.TXT "REN *.TXT *-S1.TXT" will result in the file TEST1.TXT being renamed to The truth is, that wildcards almost never work correctly when the wildcard is in the middle of the filename. The DOS command shell, to include WinNT/2K/XP has always acted strangely when using wildcards in the middle of filenames. ~~ Remove a suffix (Remove b in a_b.c) ~~ off&for %%f in (*_*.*) do call :ProcessFile %%fįor /F "delims=_. Must remove the 'echo' from 'echo ren' to actually do the deed.
BATCH FILE RENAME DOS CODE
Some code just 'echo's the rename commands to be run. The code-author's EE id usually follows each code block. (Some of what fails: '|' after 'if' or 'call' statement '&' after 'if', '&' after 'set' as in:set x=y&if %x%=y echo y the set doesn't happen until AFTER a line break! Weird language.) Note: to echo the '&' you must 'echo ^&' See "Can you type more than one command at one command prompt?". Some code I've condensed using the '&' sign (for NT/2k/XP) or the '|' sign (for 98) which often allow use of multiple commands on one line.

(see "Please let me know" under 'Remove a prefix' below).
BATCH FILE RENAME DOS FREE
> Still nothing? Then points to whoever locates free internet documentation of the ":~4%" feature as used in a rename command.

(& If solution also works in Win98, Joy! :)) > Failing that, then points to any rename routine that's uniquely functional and worthy of being added to this collection. > A general "find & replace" to rename files in a folder: the MS-DOS code must replace a specified string in any part of a name with another specified string (which may be null or other).
BATCH FILE RENAME DOS PLUS
The compilation, plus my own code that follows, took well over 12 hours of work in research, tests, & getting this together. BELOW IS A COLLECTION OF MANY MS-DOS FILE-RENAME ROUTINES, from EE, FOR A VARIETY OF NEEDS.ĪLL HERE IN ONE PLACE, FOR YOUR EASE & PLEASURE : )
