{"id":984,"date":"2010-10-20T04:23:57","date_gmt":"2010-10-19T22:53:57","guid":{"rendered":"http:\/\/mohamediqbalp.wordpress.com\/2010\/10\/20\/top-20-dos-file-rename-routines\/"},"modified":"2010-10-20T04:23:57","modified_gmt":"2010-10-19T22:53:57","slug":"top-20-dos-file-rename-routines","status":"publish","type":"post","link":"https:\/\/venusimportexport.com\/wordpress\/index.php\/2010\/10\/20\/top-20-dos-file-rename-routines\/","title":{"rendered":"TOP 20 DOS FILE-RENAME ROUTINES"},"content":{"rendered":"<p><span class=\"questionBody\">BELOW IS A COLLECTION OF MANY &nbsp;MS-DOS FILE-RENAME ROUTINES, &nbsp;from &#8220;<a target=\"_blank\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html\">Experts Exchange<\/a>&#8220;, FOR A VARIETY OF NEEDS.<br \/>ALL HERE IN ONE PLACE, FOR YOUR EASE &amp; PLEASURE &nbsp; &nbsp;: )<\/p>\n<p>N o t e s :<br \/>&#8211; Some code is <br \/>condensed using the &#8216;&amp;&#8217; sign (for NT\/2k\/XP) or the &#8216;|&#8217; sign (for 98)<br \/> which often allow use of multiple commands on one line. See <a href=\"http:\/\/computerhope.com\/issues\/ch000177.htm\" target=\"_blank\">http:\/\/computerhope.com\/issues\/ch000177.htm<\/a><br \/> &#8220;Can you type more than one command at one command prompt?&#8221;. (Some of <br \/>what fails: &nbsp;&#8216;|&#8217; after &#8216;if&#8217; or &#8216;call&#8217; statement; &#8216;&amp;&#8217; &nbsp;after &#8216;if&#8217;, <br \/>&#8216;&amp;&#8217; after &#8216;set&#8217; as in:set x=y&amp;if &nbsp;%x%==y echo y; the set doesn&#8217;t<br \/> happen until AFTER a line break! Weird language&#8230;) Note: to echo the <br \/>&#8216;&amp;&#8217; &nbsp;you must &#8216;echo ^&amp;&#8217;<br \/>-The code-author&#8217;s EE id usually follows each code block.<br \/>-Some code &nbsp;just &#8216;echo&#8217;s the rename commands to be run. Must remove the &#8216;echo&#8217; from &#8216;echo ren&#8217; to actually do the deed.<\/p>\n<p>~~ Add a suffix (*_n): ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21678938.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21678938.html<\/a><br \/>FOR %%f IN (*.*) DO ren %%f %%f_n<br \/>::mgh_mgharish <\/p>\n<p>~~ Remove a suffix (Remove b in &nbsp; a_b.c) ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Programming\/Q_21506296.html\">http:\/\/www.experts-exchange.com\/Programming\/Q_21506296.html<\/a><br \/>@echo off&amp;for %%f in (*_*.*) do call :ProcessFile %%f<br \/>goto :eof<br \/>:ProcessFile<br \/>for \/F &#8220;delims=_. tokens=1,3&#8221; %%c in (&#8220;%1&#8221;) do echo ren &#8220;%1&#8221; &#8220;%%c.%%d&#8221;<br \/>::Adam314 <\/p>\n<p>~~ Add a prefix (S1*): ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20591441.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20591441.html<\/a><br \/>for %%i in (*.*) do move %%i s1%%i &nbsp; <br \/>::bryancw <br \/>for \/f &#8220;delims=&#8221; %i in (&#8216;dir\/b&#8217;) do ren &#8220;%i&#8221; &#8220;s1%i&#8221;<br \/>::ManuelGuerra <\/p>\n<p>::pbarrette <br \/>The DOS command shell, to include WinNT\/2K\/<a id=\"KonaLink0\" target=\"undefined\" class=\"kLink\" style=\"text-decoration:underline!important;position:static;\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html#\"><font color=\"blue\"><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">XP<\/span><\/font><\/a><br \/> has always acted strangely when using wildcards in the middle of <br \/>filenames. The truth is, that wildcards almost never work correctly when<br \/> the wildcard is in the middle of the filename.<br \/>For example:<br \/>&#8220;REN *.TXT *-S1.TXT&#8221; will result in the file TEST1.TXT being renamed to TEST1.TXT-S1.TXT<br \/>&#8220;REN *.TXT S1-*.TXT&#8221; will result in the file TEST1.TXT being renamed to S1-T1.TXT<\/p>\n<p>~~ Remove a prefix &#8212; a fixed # of bytes. Replace with new prefix. (SFyymmddhhmm.csv-&gt;SISCR12mmddhhmm.csv ) ~~<br \/>*** &#8220;:~4%&#8221; crop feature: where is it documented? Please let me know&#8230; &#8211; callrs***<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20784641.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20784641.html<\/a><br \/>@echo off<br \/>for %%i in (SF03*.CSV) do (set fname=%%i) &amp; call :rename<br \/>goto :eof<br \/>:rename<br \/>::Cuts off 1st 4 characters of fname, then appends prefix<br \/>ren %fname% SISCR12%fname:~4%<br \/>goto :eof<br \/>::-SethHoyt <\/p>\n<p>&nbsp;<br \/>~~ Add a prefix to numbers-only file-name: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21474433.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21474433.html<\/a><br \/>for \/f %%a in (&#8216;dir \/b *.txt ^| findstr \/I \/X \/R \/C:^[0-9]*.txt&#8217;) do ren %%a prefix%%a<br \/>::or for 8-digit files only:<br \/>for \/f %%a in (&#8216;dir \/b *.txt ^| findstr \/I \/X \/R \/C:^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt&#8217;) do ren %%a pyxbl%%a<br \/>::mpfister <\/p>\n<p>~~ Rename to random number: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinNT\/Q_20781578.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinNT\/Q_20781578.html<\/a><br \/>@echo off&amp;setlocal<br \/>set FileMask=*.bmp<br \/>for \/f &#8220;tokens=*&#8221; %%a in (&#8216;dir \/b \/a:-d &#8220;%FileMask%&#8221;&#8216;) do call :process &#8220;%%a&#8221;<br \/>goto :eof<br \/>:process<br \/>:loop<br \/>set rnd=%Random%<br \/>if exist %rnd%%~x1 goto loop<br \/>ECHO ren %1 %rnd%%~x1<br \/>goto :eof<br \/>::oBdA <\/p>\n<p>~~ ??? wildcards ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Miscellaneous\/Q_21623266.html\">http:\/\/www.experts-exchange.com\/Miscellaneous\/Q_21623266.html<\/a><br \/>ren ???xxx??? ???zzz???<br \/>::paraghs <\/p>\n<p>~~ Recurse through all sub-directories (excluding current), changing extension: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21328624.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21328624.html<\/a><br \/>@echo off<br \/>for \/f &#8220;tokens=1 delims=&#8221; %%a in (&#8216;dir \/s \/b \/ad&#8217;) do if exist &#8220;%%a*.asp&#8221; echo ren &#8220;%%a*.asp&#8221; *.<a id=\"KonaLink1\" target=\"undefined\" class=\"kLink\" style=\"text-decoration:underline!important;position:static;\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html#\"><font color=\"blue\"><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">html<\/span><\/font><\/a> &gt;&gt; rename.cmd<br \/>::leew <\/p>\n<p>~~ Rename all jpg files in a folder tree (to cover.jpg): ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20696712.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20696712.html<\/a><br \/>@for \/R c: %%f in (*.jpg) do echo rename &#8220;%%~ff&#8221; cover.jpg<br \/>::SteveGTR <\/p>\n<p>~~ Recurse thru sub-directories, renaming files ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_20849138.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_20849138.html<\/a><br \/>FOR \/r %1 IN (.) do MYRENAMEBAT.BAT %1<br \/>::RaviPal . &nbsp; Where the bat file is:<br \/>@echo off&amp;echo This will rename all files containing &#8216;_fixed&#8217;.<br \/>echo CHANGE THE FOLDER&amp;cd %1&amp;Pause<br \/>rename *_fixed.zip *.xxx<br \/>rename *.zip *.zip.old<br \/>Rename *.xxx *.zip<\/p>\n<p>~~ Suffix a date: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Miscellaneous\/Games\/DOS_Games\/Q_10314402.html\">http:\/\/www.experts-exchange.com\/Miscellaneous\/Games\/DOS_Games\/Q_10314402.html<\/a><br \/>ren c:tempabc.txt abc%date:~4,2%-%date:~7,2%-%date:~10%.txt<br \/>::temadan<\/p>\n<p><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21625029.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21625029.html<\/a><br \/>@echo off&amp;if [%1]==[] goto :usage<br \/>set strFile=%1<br \/>set strExt=%strFile:~-4%<br \/>set strNew=%strFile:~0,-4%<br \/>ren strFile %strNew%%date:~6,4%%date:~0,2%%date:~3,2%.%strExt%<br \/>goto :eof<br \/>:usage<br \/>RenFile OriginalFilename<br \/>::sirbounty <\/p>\n<p>~~ Copy, adding system date: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20611296.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20611296.html<\/a><br \/>@ECHO OFF<br \/>FOR \/F &#8220;TOKENS=2-4 DELIMS=\/ &#8221; %%F IN (&#8216;DATE \/T&#8217;) DO (SET TODAY=%%F%%G%%H)<br \/>COPY \/Y \/B C:TEMP*.VCH C:UploadCombined.vch<br \/>REN C:UploadCombined.vch Combined-%TODAY%.vch<br \/>::pbarrette <\/p>\n<p>~~ Rename jpg files to their file-time-stamp: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_20805899.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_20805899.html<\/a><br \/>@ECHO OFF<br \/>FOR<br \/> %%V IN (*.jpg) DO FOR \/F &#8220;tokens=1-5 delims=\/: &#8221; %%J &nbsp;IN (&#8220;%%~tV&#8221;) DO <br \/>IF EXIST %%L%%J%%K_%%M%%N%%~xV (ECHO Cannot rename %%V) ELSE (ECHO <br \/>RENAME &#8220;%%V&#8221; %%L%%J%%K_%%M%%N%%~xV &amp; RENAME &#8220;%%V&#8221; <br \/>%%L%%J%%K_%%M%%N%%<br \/>\n~xV)<br \/>::From PC-Mag<br \/>::arjanh <\/p>\n<p>~~ Copy, appending current date: ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21554862.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21554862.html<\/a> <br \/>@echo off&amp;setlocal<br \/>::Change these as necessary<br \/>set Source=d:temp&amp;set Dest=d:temp2<br \/>if &#8220;%Source:~-1%&#8221; NEQ &#8220;&#8221; set Source=%Source%<br \/>if &#8220;%Dest:~-1%&#8221; NEQ &#8220;&#8221; set Dest=%Dest%<br \/>if not exist %Source% goto :Error<br \/>if not exist %Dest% goto :Error<br \/>set Today=%date:~0,2%%date:~3,2%%date:~6,4%<br \/>for %%z in (%Source%*.*) do call :ProcessFile &#8220;%%z&#8221;<br \/>goto :eof<br \/>:ProcessFile<br \/>set FilePath=%~1&amp;set FileName=%~n1&amp;set FileExt=%~x1<br \/>::Remove the echo from the next line to do the actual copy<br \/>echo copy &#8220;%FilePath%&#8221; &#8220;%Dest%%FileName%_%Today%%FileExt%&#8221;<br \/>goto :eof<br \/>:Error<br \/>echo Either the source or destination directory does not exist<br \/>::Adam314 <\/p>\n<p>~~ Date Image Files based on date taken etc. ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21374636.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinXP\/Q_21374636.html<\/a><br \/>&#8211; <a href=\"http:\/\/www.hugsan.com\/EXIFutils\/html\/features.html\" target=\"_blank\">http:\/\/www.hugsan.com\/EXIFutils\/html\/features.html<\/a> Rename <a id=\"KonaLink2\" target=\"undefined\" class=\"kLink\" style=\"text-decoration:underline!important;position:static;\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html#\"><font color=\"blue\"><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">image <\/span><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">files<\/span><\/font><\/a> based on the value of EXIF and IPTC fields<br \/>&#8211; <a href=\"http:\/\/www.kuren.org\/exif\/\" target=\"_blank\">http:\/\/www.kuren.org\/exif\/<\/a> How to read EXIF Tags &nbsp;(Similar to above)<br \/>&#8211; <a href=\"http:\/\/www.unidreamtech.com\/index.php\" target=\"_blank\">http:\/\/www.unidreamtech.com\/index.php<\/a> Powerbatch<br \/>&#8211; <a href=\"http:\/\/www.stuffware.co.uk\/photostudio\/\" target=\"_blank\">http:\/\/www.stuffware.co.uk\/photostudio\/<\/a> Photo Studio<br \/>&#8211; <a href=\"http:\/\/djernaes.dk\/download\/jpegdate14.zip\" target=\"_blank\">http:\/\/djernaes.dk\/download\/jpegdate14.zip<\/a> &nbsp;&#8211; <a href=\"http:\/\/big.park.se\/files\/extra\/exchange\/jpgdate.zip\" target=\"_blank\">http:\/\/big.park.se\/files\/extra\/exchange\/jpgdate.zip<\/a><\/p>\n<p>~~ Rename all files to 3-digit Number (001, 002, &#8230;): ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21062570.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21062570.html<\/a><br \/>:: Change c:temp1 with the folder your files are in. Don&#8217;t put .bat files in that folder.<br \/>@echo off&amp;setlocal&amp;set count=0<br \/>for \/f &#8220;usebackq delims=&#8221; %%x in (`dir \/a:-d \/b &#8220;C:TEMP*.*&#8221;`) DO CALL :NUMBER %%x<br \/>goto :EOF<br \/>:NUMBER<br \/>set NAME=%~n1%<br \/>set EXT=00%count%<br \/>set EXT=%EXT:~-3%<br \/>echo ren &#8220;%1&#8221; &#8220;%NAME%.%EXT%&#8221;<br \/>set \/a count+=1<br \/>goto :EOF<br \/>::MaartenG (-)<br \/>&#8211;&gt;Below is MS-DOS 6 version, with c:temp1 being path to files to rename.<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; rename00.bat<br \/>ECHO OFF|set n1=0|set n2=0|set n3=0<br \/>for %%a in (c:temp1*.*) do call renameit.bat %%a<br \/>set n1=|set n2=|set n3=|set nx=<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; renameit.bat<br \/>rename %1 %n3%%n2%%n1%<br \/>set nx=%n1%| call incnx.bat<br \/>set n1=%nx%<br \/>if not %n1%==0 goto end<br \/>set nx=%n2%| call incnx.bat<br \/>set n2=%nx%<br \/>if not %n2%==0 goto end<br \/>set nx=%n3%| call incnx.bat<br \/>set n3=%nx%<br \/>:end<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- incnx.bat<br \/>if %nx%==0 goto number0<br \/>if %nx%==9 SET nx=0<br \/>if %nx%==8 SET nx=9<br \/>if %nx%==7 SET nx=8<br \/>if %nx%==6 SET nx=7<br \/>if %nx%==5 SET nx=6<br \/>if %nx%==4 SET nx=5<br \/>if %nx%==3 SET nx=4<br \/>if %nx%==2 SET nx=3<br \/>if %nx%==1 SET nx=2<br \/>goto end<br \/>:number0<br \/>SET nx=1<br \/>:end<br \/>::For-Soft<\/p>\n<p>~~ Rename all files to prefix + a number &nbsp;(images_1.jpg, images_2.jpg &#8230;) ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21347867.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21347867.html<\/a><br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21536842.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21536842.html<\/a><br \/>@echo off&amp;set \/a cnt=1<br \/>for %%a in (*.jpg) do call :PROCESS &#8220;%%a&#8221;<br \/>goto :EOF<br \/>:PROCESS<br \/>echo rename %1 images_%cnt%.jpg<br \/>set \/a cnt+=1<br \/>::SteveGTR <\/p>\n<p>~~ Replace First Dot ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/Win2000\/Q_20596712.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/Win2000\/Q_20596712.html<\/a><br \/>@echo off&amp;setlocal&amp;echo.&amp;set Test=FALSE<br \/>if %1.==. goto Syntax<br \/>if %1==\/? goto Syntax<br \/>if %1==-? goto Syntax<br \/>if %2.==. goto :begin<br \/>if \/i not %2==\/test goto Syntax<br \/>set Test=TRUE<br \/>:begin<br \/>for \/f %%a in (&#8216;dir \/b \/a:-d %1&#8217;) do (<br \/>&nbsp; set FilePath=%%~dpa&amp;set FileName=%%~na&amp;set FileExt=%%~xa&amp;call :process )<br \/>goto :eof<br \/>:process<br \/>if %FileName%==%FileName:.=% goto :eof<br \/>for \/f &#8220;tokens=1* delims=.&#8221; %%a in (&#8220;%FileName%&#8221;) do set NewFileName=%%a-%%b<br \/>echo %FilePath%%FileName%%FileExt% &#8211;^&gt; %NewFileName%%FileExt%<br \/>if \/i %Test%==TRUE goto :eof<br \/>ren &#8220;%FilePath%%FileName%%FileExt%&#8221; &#8220;%NewFileName%%FileExt%&#8221;<br \/>goto :eof<br \/>:Syntax<br \/>echo %~nx0&amp;echo.<br \/>echo Replaces first &#8220;.&#8221;, if any, of the file name with a &#8220;-&#8220;, but not the extension&amp;echo.<br \/>echo Syntax: &nbsp;&amp;echo repdot ^&lt;File^&gt; [\/test]&amp;echo.<br \/>echo ^&lt;File^&gt;: The specified directory\/file is processed<br \/>echo \/test: &nbsp;No renaming is done, files that would be renamed are only displayed.<br \/>echo.<br \/>::oBdA <\/p>\n<p>~~ Move tokens around ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/WinNT\/Q_20686191.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/WinNT\/Q_20686191.html<\/a><br \/>@echo off&amp;setlocal&amp;set Folder=%1&amp;set Pattern=samptest.txt.*<br \/>dir \/b %Folder%%Pattern% 1&gt;NUL 2&gt;NUL<br \/>if errorlevel 1 goto Syntax<br \/>for \/f %%a in (&#8216;dir \/b %Folder%%Pattern%&#8217;) do (<br \/>&nbsp; set File=%%a&amp; &nbsp;call :process)<br \/>goto :eof<br \/>:process<br \/>echo Processing %File% &#8230;<br \/>for \/f &#8220;tokens=1-3 delims=.&#8221; %%a in (&#8220;%File%&#8221;) do (<br \/>&nbsp; set Name=%%a<br \/>&nbsp; set Number=%%c)<br \/>set NewFile=%Name%%Number%.edi<br \/>:: *** Remove the &#8220;echo&#8221; in the next line to &#8220;arm&#8221; the script<br \/>echo ren %Folder%%File% %NewFile%<br \/>goto :eof<br \/>:Syntax<br \/>echo.&amp;<br \/>echo ediren.cmd&amp;echo.<br \/>echo Renames files matching samptest.txt.^&lt;Number^&gt;<br \/>echo to samptest^&lt;Number^&gt;.edi&amp;echo.&amp;echo Syntax:<br \/>echo ediren [^&lt;Target Directory^&gt;]&amp;echo.<br \/>echo If no target directory is specified, the current directory is used.<br \/>echo The directory must be specified including the trailing &#8220;&#8221;!<br \/>echo.<br \/>::oBdA <\/p>\n<p>~~ Other ~~<br \/><a href=\"http:\/\/www.experts-exchange.com\/Programming\/Programming_Languages\/C\/Q_20124580.html\">http:\/\/www.experts-exchange.com\/Programming\/Programming_Languages\/C\/Q_20124580.html<\/a><br \/>MoveFile &#8211; Rename an existing file or a directory <br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20721695.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_20721695.html<\/a><br \/>renaming files but exclude newest<br \/><a href=\"http:\/\/www.experts-exchange.com\/Programming\/Programming_Languages\/Cplusplus\/Q_20929292.html\">http:\/\/www.experts-exchange.com\/Programming\/Programming_Languages\/Cplusplus\/Q_20929292.html<\/a><br \/>Comparing,moving, and renaming files in a DOS atmosphere<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21587969.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/MSDOS\/Q_21587969.html<\/a><br \/>A batch rena<br \/>\nme operation which cannot be done with dos, can someone do it in\/with vbscript?<\/p>\n<p>~~ General Renaming Utilities referenced in posts: * means <a id=\"KonaLink3\" target=\"undefined\" class=\"kLink\" style=\"text-decoration:underline!important;position:static;\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html#\"><font color=\"blue\"><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">freeware<\/span><\/font><\/a> ~~<br \/><a href=\"http:\/\/www.snapfiles.com\/freeware\/system\/fwfilerename.html\" target=\"_blank\">http:\/\/www.snapfiles.com\/freeware\/system\/fwfilerename.html<\/a> File Renaming Tools*<br \/><a href=\"http:\/\/www.bulkrenameutility.co.uk\/Main_Intro.php\" target=\"_blank\">http:\/\/www.bulkrenameutility.co.uk\/Main_Intro.php<\/a> Bulk Rename Utility*<br \/><a href=\"https:\/\/sourceforge.net\/projects\/renameit\/\" target=\"_blank\">https:\/\/sourceforge.net\/projects\/renameit\/<\/a> &nbsp;<a href=\"http:\/\/www.beroux.com\/renameit\/\" target=\"_blank\">http:\/\/www.beroux.com\/renameit\/<\/a> Opensource Rename-it*<br \/><a href=\"http:\/\/www.joejoesoft.com\/vcms\/108\/\" target=\"_blank\">http:\/\/www.joejoesoft.com\/vcms\/108\/<\/a> Rename Master*<br \/><a href=\"http:\/\/www.kellysoftware.com\/software\/Rename4u.asp\" target=\"_blank\">http:\/\/www.kellysoftware.com\/software\/Rename4u.asp<\/a> Rename4u (Kelly <a id=\"KonaLink4\" target=\"undefined\" class=\"kLink\" style=\"text-decoration:underline!important;position:static;\" href=\"http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/Q_21873735.html#\"><font color=\"blue\"><span class=\"kLink\" style=\"color:blue!important;font-family:arial,helvetica,sans-serif;font-weight:400;font-size:12px;position:static;\">Software<\/span><\/font><\/a>)*<br \/><a href=\"http:\/\/www.azheavymetal.com\/%7Elupasrename\/news.php\" target=\"_blank\">http:\/\/www.azheavymetal.com\/~lupasrename\/news.php<\/a> Lupas Rename 2000*<br \/><a href=\"http:\/\/www.irfanview.com\/\" target=\"_blank\">http:\/\/www.irfanview.com\/<\/a> &nbsp;IrfanView* (File&#8211;&gt;Batch Conversion\/Rename&#8230;)<br \/><a href=\"http:\/\/www.publicspace.net\/windows\/BetterFileRename\/\" target=\"_blank\">http:\/\/www.publicspace.net\/windows\/BetterFileRename\/<\/a> Better File Rename (Not Free)<br \/><a href=\"http:\/\/www.123renamer.com\/buy.htm\" target=\"_blank\">http:\/\/www.123renamer.com\/buy.htm<\/a> File and MP3 Tag Renamer (Trial)<\/p>\n<p>~~ Below is my own code from answer to &#8220;Rename Files Instantaneously&#8221;:<br \/><a href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/Win98\/Q_21864152.html\">http:\/\/www.experts-exchange.com\/Operating_Systems\/Win98\/Q_21864152.html<\/a> ~~<br \/>=================================================renlef+.bat<br \/>:: renlef+.bat<br \/>::<br \/> Prefix ADD utility for file names: Adds the specified prefix and delim <br \/>(&amp; optionally isolates delim by spaces) to all files that have <br \/>specified extension<br \/>:: Doesn&#8217;t perform the rename, but generates &amp; &nbsp;writes the commands to a bat file<br \/>:: If prefix+delim is already in the original name, then ignores the file unless doall=1<br \/>::<br \/>:: Arguments:<br \/>:: &nbsp; %1 &#8211; Prefix to add<br \/>:: &nbsp; %2 &#8211; Delimiter to add<br \/>:: &nbsp; %3 &#8211; Extension of file<br \/>:: &nbsp; %4 &#8211; Space &#8211; Set to 1 to add space to both sides of delim<br \/>:: &nbsp; %5 &#8211; Doall &#8211; See &#8220;If prefix+delim&#8230;&#8221; note above<br \/>::<br \/>:: v1.01 &nbsp;By Ravinder Singh (&#8216;wiz&#8217; on the quickmacros forum), May 26, 2006<br \/>::<br \/>::<br \/>:: if exists renlef+_.bat goto FILEEXISTS<br \/>@echo off<br \/>setlocal<br \/>set outfile=renlef+_<br \/>if exist &#8220;%outfile%.bat&#8221; del &#8220;%outfile%.bat&#8221;<br \/>if %1.==. (set \/a exitcode=98&amp;goto USAGE)<br \/>if %2.==. (set \/a exitcode=98&amp;goto USAGE)<br \/>set adn=%1&amp;set delm=%2&amp;set ext=%3&amp;set space=%4&amp;set doall=%5&amp;&amp;set count=0<br \/>if %doall%.==1. goto SIMPLE<\/p>\n<p>for %%a in (*.%ext%) do (<br \/>if %space%.==1. (<br \/>&nbsp; &nbsp; &nbsp;echo %%a| find &#8220;%adn% %delm% &#8220;<br \/>&nbsp; &nbsp; &nbsp;if errorlevel 1 (set \/a count+=1&amp;echo ren &#8220;%%a&#8221; &#8220;%adn% %delm% %%a&#8221; &nbsp;&gt;&gt; &#8220;%outfile%.bat&#8221; ))<br \/>if NOT %space%.==1. (<br \/>&nbsp; &nbsp; &nbsp; echo %%a | find &#8220;%adn%%delm%&#8221;<br \/>&nbsp; &nbsp; &nbsp;if errorlevel 1 (set \/a count+=1&amp;echo ren &#8220;%%a&#8221; &#8220;%adn%%delm%%%a&#8221; &gt;&gt; &#8220;%outfile%.bat&#8221; &nbsp; &nbsp; ))<br \/>)<br \/>goto :DONE<br \/>:SIMPLE<br \/>:: &nbsp;separated routine here &#8217;cause wasn&#8217;t able to integrate &#8217;cause of weird behaviour in msdos on Win2K<br \/>:: e.g. if you SET XX=YY, then echo &#8220;%XX%&#8221; doesn&#8217;t give us XX&#8217;s value within a FOR loop, but only on exit from loop<br \/>for %%a in (*.%ext%) do (<br \/>&nbsp; &nbsp; &nbsp;set \/a count+=1<br \/>&nbsp; &nbsp; &nbsp;if %space%.==1. echo ren &#8220;%%a&#8221; &#8220;%adn% %delm% %%a&#8221; &nbsp;&gt;&gt; &#8220;renlef+_.bat&#8221;<br \/>&nbsp; &nbsp; &nbsp;if NOT %space%.==1. &nbsp; &nbsp; &nbsp;echo ren &#8220;%%a&#8221; &#8220;%adn%%delm%%%a&#8221; &gt;&gt; &#8220;renlef+_.bat&#8221;)<\/p>\n<p>:DONE<br \/>if %count%==0 (<br \/>&nbsp; &nbsp; &nbsp;echo No files found that match criteria.&amp;echo.<br \/>&nbsp; &nbsp; &nbsp;set \/a exitcode=97<br \/>&nbsp; &nbsp; &nbsp;goto usage<br \/>&nbsp; &nbsp; &nbsp;)<br \/>type renlef+_.bat<br \/>echo.<br \/>echo type: %outfile% &nbsp; &nbsp; &nbsp; &nbsp; To rename the above %count% files files! Or edit %outfile%.bat<br \/>goto :EOF<\/p>\n<p>:USAGE<br \/>echo USAGE: %~nx0 &nbsp;WHAT-TO-APPEND-TO-LEFT &nbsp; DELIMETER &nbsp; EXTENSION &nbsp;SPACE? ALL?<br \/>exit \/B %exitcode%<\/p>\n<p>:FILEEXISTS<br \/>echo renall.bat exists. (Check ^&amp; ) Delete file first.<br \/>exit \/B 99<br \/>====================================================renlef-.bat<br \/>:: renlef-.bat<br \/>::<br \/> &nbsp;&#8211; Prefix REMOVAL utility for file names: Cuts the specified prefix <br \/>that precedes a space and\/or the specified delimiters in a file name <br \/>:: As a precaution:<br \/>:: &#8212; All rename commands are generated &amp; then displayed on screen<br \/>:: &#8212; All rename commands are written to a file which can be run &nbsp;(after any optional or required user&#8217;s edits)<br \/>::<br \/>:: Arguments:<br \/>:: &nbsp; &nbsp;%1 &#8211; Word to remove<br \/>:: &nbsp; &nbsp;%2 &#8211; Optional delimiters, in addition to the default space, that separate %1 from the part you want to keep<br \/>:: &nbsp; &nbsp;%3 &#8211; Extension of file<br \/>::<br \/>:: E.g. to remove initial &#8220;PART&#8221; from all files that start with &#8220;PART # &#8220;:<br \/>:: &nbsp; &nbsp; renlef- PART #<br \/>::<br \/>:: v1.01 By Ravinder Singh (&#8216;wiz&#8217; on the quickmacros forum), May 26, 2006<br \/>::<br \/>@echo off<br \/>setlocal<br \/>if %1.==. (set \/a exitcode=98&amp;goto usage)<br \/>set cut=%1&amp;set delims=%2&amp;set ext=%3&amp;set outfile=renlef-_&amp;set count=0<br \/>if exist &#8220;%outfile%.bat&#8221; del &#8220;%outfile%.bat&#8221;<br \/>::if not exist &nbsp;&#8220;%outfile%.bat&#8221; set writeToFile=1<br \/>set writeToFile=1<\/p>\n<p>:: Let user see and verify all rename commands before we execute them<br \/>for \/f &#8220;usebackq delims=&#8221; %%i in (`dir \/b %cut%*.%ext%`) do @call :TEST &#8220;%%i&#8221;<\/p>\n<p>if %count%==0 (<br \/>&nbsp; &nbsp; &nbsp;echo No files found that match criteria.&amp;echo.<br \/>&nbsp; &nbsp; &nbsp;set \/a exitcode=97<br \/>&nbsp; &nbsp; &nbsp;goto usage<br \/>&nbsp; &nbsp; &nbsp;)<br \/>echo.<br \/>echo type: %outfile% &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; To rename the above %count% files! Or edit %outfile%.bat<br \/>goto :EOF<br \/>::1*<\/p>\n<p>:TEST<br \/>set \/a count+=1<br \/>set name=%1<br \/>FOR \/f &nbsp;&#8220;usebackq tokens=1,2,3 delims=%delims% &#8221; %%j IN (`echo %name%`) DO @set mycmd=ren %name% &#8220;%%k<br \/>echo %mycmd%<br \/>if %writeToFile%==1 echo %mycmd% &gt;&gt; %outfile%.bat<br \/>goto :EOF<\/p>\n<p>:usage<br \/>echo usage: %~nx0 &nbsp; LEFT-TRIM-STRING &nbsp; DELIMS &nbsp; &nbsp;EXTENSION<br \/>exit \/B %exitcode%<\/p>\n<p>:: Other notes<br \/>::<br \/>:: original basic routine, with delimiters being &#8220;- &#8220;<br \/>::for \/f &#8220;usebackq tokens=1,2,3 &nbsp;delims=- &#8221; %%i in (`dir \/b %1*`) do echo ren &#8220;%%i &#8211; %%j&#8221; &#8220;%%j&#8221;<br \/>::<br \/>:: 1* &#8212; Optional code, can use if you don&#8217;t want to create %output%.bat<br \/>:: Now prompt whether or not to do the batch rename<br \/>set\/p input=Enter y to execute the above commands, anything else to quit: &nbsp;<br \/>if not %input%.==y. goto :EOF<br \/>for \/f &#8220;usebackq delims=&#8221; %%i<br \/>\n in (`dir \/b %cut%*.%ext%`) do @call :RENAMEALL &#8220;%%i&#8221;<br \/>goto :EOF<br \/>:RENAMEALL<br \/>set name=%1<br \/>FOR \/f &nbsp;&#8220;usebackq tokens=1,2,3 delims=%delims% &#8221; %%j IN (`echo %name%`) DO ren %name% &#8220;%%k<br \/>goto :EOF<\/span><\/p>\n<div class=\"zemanta-pixie\"><img decoding=\"async\" class=\"zemanta-pixie-img\" alt=\"\" src=\"http:\/\/img.zemanta.com\/pixy.gif?x-id=5fa85c66-728e-8fc7-9872-ea6580ad60ba\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>BELOW IS A COLLECTION OF MANY &nbsp;MS-DOS FILE-RENAME ROUTINES, &nbsp;from &#8220;Experts Exchange&#8220;, FOR A VARIETY OF NEEDS.ALL HERE IN ONE PLACE, FOR YOUR EASE &amp; PLEASURE &nbsp; &nbsp;: ) N o t e s :&#8211; Some code is condensed using the &#8216;&amp;&#8217; sign (for NT\/2k\/XP) or the &#8216;|&#8217; sign (for 98) which often allow use&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/venusimportexport.com\/wordpress\/index.php\/2010\/10\/20\/top-20-dos-file-rename-routines\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-984","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=984"}],"version-history":[{"count":0,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/984\/revisions"}],"wp:attachment":[{"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/venusimportexport.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}