Question

RENAME FILES USING PURE MS-DOS

Asked by: callrs

BELOW IS A COLLECTION OF MANY  MS-DOS FILE-RENAME ROUTINES,  from EE, FOR A VARIETY OF NEEDS.
ALL HERE IN ONE PLACE, FOR YOUR EASE & PLEASURE    : )
The compilation, plus my own code that follows, took well over 12 hours of work in research, tests, & getting this together.

My Request? One or more of:
-> 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). You can use the info below to help out.  Anyone up for the  challenge?

-> Failing that, then points  to any rename routine that's uniquely functional and worthy of being added to this collection.  (& If solution also works in Win98, Joy! :))

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

N o t e s :
- 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 http://computerhope.com/issues/ch000177.htm "Can you type more than one command at one command prompt?". (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 ^&'
-The code-author's EE id usually follows each code block.
-Some code  just 'echo's the rename commands to be run. Must remove the 'echo' from 'echo ren' to actually do the deed.


~~ Add a suffix (*_n): ~~
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21678938.html
FOR %%f IN (*.*) DO ren %%f %%f_n
::mgh_mgharish

~~ Remove a suffix (Remove b in   a_b.c) ~~
http://www.experts-exchange.com/Programming/Q_21506296.html
@echo off&for %%f in (*_*.*) do call :ProcessFile %%f
goto :eof
:ProcessFile
for /F "delims=_. tokens=1,3" %%c in ("%1") do echo ren "%1" "%%c.%%d"
::Adam314


~~ Add a prefix (S1*): ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20591441.html
for %%i in (*.*) do move %%i s1%%i  
::bryancw
for /f "delims=" %i in ('dir/b') do ren "%i" "s1%i"
::ManuelGuerra

::pbarrette
The DOS command shell, to include WinNT/2K/XP has always acted strangely when using wildcards in the middle of filenames. The truth is, that wildcards almost never work correctly when the wildcard is in the middle of the filename.
For example:
"REN *.TXT *-S1.TXT" will result in the file TEST1.TXT being renamed to TEST1.TXT-S1.TXT
"REN *.TXT S1-*.TXT" will result in the file TEST1.TXT being renamed to S1-T1.TXT

~~ Remove a prefix -- a fixed # of bytes. Replace with new prefix. (SFyymmddhhmm.csv->SISCR12mmddhhmm.csv ) ~~
*** ":~4%" crop feature: where is it documented? Please let me know... - callrs***
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20784641.html
@echo off
for %%i in (SF03*.CSV) do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off 1st 4 characters of fname, then appends prefix
ren %fname% SISCR12%fname:~4%
goto :eof
::-SethHoyt

 
~~ Add a prefix to numbers-only file-name: ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21474433.html
for /f %%a in ('dir /b *.txt ^| findstr /I /X /R /C:^[0-9]*.txt') do ren %%a prefix%%a
::or for 8-digit files only:
for /f %%a in ('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') do ren %%a pyxbl%%a
::mpfister

~~ Rename to random number: ~~
http://www.experts-exchange.com/Operating_Systems/WinNT/Q_20781578.html
@echo off&setlocal
set FileMask=*.bmp
for /f "tokens=*" %%a in ('dir /b /a:-d "%FileMask%"') do call :process "%%a"
goto :eof
:process
:loop
set rnd=%Random%
if exist %rnd%%~x1 goto loop
ECHO ren %1 %rnd%%~x1
goto :eof
::oBdA

~~ ??? wildcards ~~
http://www.experts-exchange.com/Miscellaneous/Q_21623266.html
ren ???xxx??? ???zzz???
::paraghs


~~ Recurse through all sub-directories (excluding current), changing extension: ~~
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21328624.html
@echo off
for /f "tokens=1 delims=" %%a in ('dir /s /b /ad') do if exist "%%a\*.asp" echo ren "%%a\*.asp" *.html >> rename.cmd
::leew

~~ Rename all jpg files in a folder tree (to cover.jpg): ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20696712.html
@for /R c:\ %%f in (*.jpg) do echo rename "%%~ff" cover.jpg
::SteveGTR

~~ Recurse thru sub-directories, renaming files ~~
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_20849138.html
FOR /r %1 IN (.) do MYRENAMEBAT.BAT %1
::RaviPal .   Where the bat file is:
@echo off&echo This will rename all files containing '_fixed'.
echo CHANGE THE FOLDER&cd %1&Pause
rename *_fixed.zip *.xxx
rename *.zip *.zip.old
Rename *.xxx *.zip


~~ Suffix a date: ~~
http://www.experts-exchange.com/Miscellaneous/Games/DOS_Games/Q_10314402.html
ren c:\temp\abc.txt abc%date:~4,2%-%date:~7,2%-%date:~10%.txt
::temadan

http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21625029.html
@echo off&if [%1]==[] goto :usage
set strFile=%1
set strExt=%strFile:~-4%
set strNew=%strFile:~0,-4%
ren strFile %strNew%%date:~6,4%%date:~0,2%%date:~3,2%.%strExt%
goto :eof
:usage
RenFile OriginalFilename
::sirbounty

~~ Copy, adding system date: ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20611296.html
@ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
COPY /Y /B C:\TEMP\*.VCH C:\Upload\Combined.vch
REN C:\Upload\Combined.vch Combined-%TODAY%.vch
::pbarrette


~~ Rename jpg files to their file-time-stamp: ~~
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_20805899.html
@ECHO OFF
FOR %%V IN (*.jpg) DO FOR /F "tokens=1-5 delims=/: " %%J  IN ("%%~tV") DO IF EXIST %%L%%J%%K_%%M%%N%%~xV (ECHO Cannot rename %%V) ELSE (ECHO RENAME "%%V" %%L%%J%%K_%%M%%N%%~xV & RENAME "%%V" %%L%%J%%K_%%M%%N%%~xV)
::From PC-Mag
::arjanh

~~ Copy, appending current date: ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21554862.html
@echo off&setlocal
::Change these as necessary
set Source=d:\temp\&set Dest=d:\temp2\
if "%Source:~-1%" NEQ "\" set Source=%Source%\
if "%Dest:~-1%" NEQ "\" set Dest=%Dest%\
if not exist %Source% goto :Error
if not exist %Dest% goto :Error
set Today=%date:~0,2%%date:~3,2%%date:~6,4%
for %%z in (%Source%*.*) do call :ProcessFile "%%z"
goto :eof
:ProcessFile
set FilePath=%~1&set FileName=%~n1&set FileExt=%~x1
::Remove the echo from the next line to do the actual copy
echo copy "%FilePath%" "%Dest%%FileName%_%Today%%FileExt%"
goto :eof
:Error
echo Either the source or destination directory does not exist
::Adam314

~~ Date Image Files based on date taken etc. ~~
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21374636.html
- http://www.hugsan.com/EXIFutils/html/features.html Rename image files based on the value of EXIF and IPTC fields
- http://www.kuren.org/exif/ How to read EXIF Tags  (Similar to above)
- http://www.unidreamtech.com/index.php Powerbatch
- http://www.stuffware.co.uk/photostudio/ Photo Studio
- http://djernaes.dk/download/jpegdate14.zip  - http://big.park.se/files/extra/exchange/jpgdate.zip


~~ Rename all files to 3-digit Number (001, 002, ...): ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21062570.html
:: Change c:\temp\1\ with the folder your files are in. Don't put .bat files in that folder.
@echo off&setlocal&set count=0
for /f "usebackq delims=" %%x in (`dir /a:-d /b "C:\TEMP\*.*"`) DO CALL :NUMBER %%x
goto :EOF
:NUMBER
set NAME=%~n1%
set EXT=00%count%
set EXT=%EXT:~-3%
echo ren "%1" "%NAME%.%EXT%"
set /a count+=1
goto :EOF
::MaartenG (-)
-->Below is MS-DOS 6 version, with c:\temp\1\ being path to files to rename.
--------------------- rename00.bat
ECHO OFF|set n1=0|set n2=0|set n3=0
for %%a in (c:\temp\1\*.*) do call renameit.bat %%a
set n1=|set n2=|set n3=|set nx=
--------------------- renameit.bat
rename %1 %n3%%n2%%n1%
set nx=%n1%| call incnx.bat
set n1=%nx%
if not %n1%==0 goto end
set nx=%n2%| call incnx.bat
set n2=%nx%
if not %n2%==0 goto end
set nx=%n3%| call incnx.bat
set n3=%nx%
:end
---------------------------- incnx.bat
if %nx%==0 goto number0
if %nx%==9 SET nx=0
if %nx%==8 SET nx=9
if %nx%==7 SET nx=8
if %nx%==6 SET nx=7
if %nx%==5 SET nx=6
if %nx%==4 SET nx=5
if %nx%==3 SET nx=4
if %nx%==2 SET nx=3
if %nx%==1 SET nx=2
goto end
:number0
SET nx=1
:end
::For-Soft

~~ Rename all files to prefix + a number  (images_1.jpg, images_2.jpg ...) ~~
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21347867.html
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21536842.html
@echo off&set /a cnt=1
for %%a in (*.jpg) do call :PROCESS "%%a"
goto :EOF
:PROCESS
echo rename %1 images_%cnt%.jpg
set /a cnt+=1
::SteveGTR


~~ Replace First Dot ~~
http://www.experts-exchange.com/Operating_Systems/Win2000/Q_20596712.html
@echo off&setlocal&echo.&set Test=FALSE
if %1.==. goto Syntax
if %1==/? goto Syntax
if %1==-? goto Syntax
if %2.==. goto :begin
if /i not %2==/test goto Syntax
set Test=TRUE
:begin
for /f %%a in ('dir /b /a:-d %1') do (
  set FilePath=%%~dpa&set FileName=%%~na&set FileExt=%%~xa&call :process )
goto :eof
:process
if %FileName%==%FileName:.=% goto :eof
for /f "tokens=1* delims=." %%a in ("%FileName%") do set NewFileName=%%a-%%b
echo %FilePath%%FileName%%FileExt% --^> %NewFileName%%FileExt%
if /i %Test%==TRUE goto :eof
ren "%FilePath%%FileName%%FileExt%" "%NewFileName%%FileExt%"
goto :eof
:Syntax
echo %~nx0&echo.
echo Replaces first ".", if any, of the file name with a "-", but not the extension&echo.
echo Syntax:  &echo repdot ^<File^> [/test]&echo.
echo ^<File^>: The specified directory/file is processed
echo /test:  No renaming is done, files that would be renamed are only displayed.
echo.
::oBdA

~~ Move tokens around ~~
http://www.experts-exchange.com/Operating_Systems/WinNT/Q_20686191.html
@echo off&setlocal&set Folder=%1&set Pattern=samptest.txt.*
dir /b %Folder%%Pattern% 1>NUL 2>NUL
if errorlevel 1 goto Syntax
for /f %%a in ('dir /b %Folder%%Pattern%') do (
  set File=%%a&  call :process)
goto :eof
:process
echo Processing %File% ...
for /f "tokens=1-3 delims=." %%a in ("%File%") do (
  set Name=%%a
  set Number=%%c)
set NewFile=%Name%%Number%.edi
:: *** Remove the "echo" in the next line to "arm" the script
echo ren %Folder%%File% %NewFile%
goto :eof
:Syntax
echo.&
echo ediren.cmd&echo.
echo Renames files matching samptest.txt.^<Number^>
echo to samptest^<Number^>.edi&echo.&echo Syntax:
echo ediren [^<Target Directory^>]&echo.
echo If no target directory is specified, the current directory is used.
echo The directory must be specified including the trailing "\"!
echo.
::oBdA


~~ Other ~~
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20124580.html
MoveFile - Rename an existing file or a directory
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20721695.html
renaming files but exclude newest
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20929292.html
Comparing,moving, and renaming files in a DOS atmosphere
http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21587969.html
A batch rename operation which cannot be done with dos, can someone do it in/with vbscript?

~~ General Renaming Utilities referenced in posts: * means freeware ~~
http://www.snapfiles.com/freeware/system/fwfilerename.html File Renaming Tools*
http://www.bulkrenameutility.co.uk/Main_Intro.php Bulk Rename Utility*
https://sourceforge.net/projects/renameit/  http://www.beroux.com/renameit/ Opensource Rename-it*
http://www.joejoesoft.com/vcms/108/ Rename Master*
http://www.kellysoftware.com/software/Rename4u.asp Rename4u (Kelly Software)*
http://www.azheavymetal.com/~lupasrename/news.php Lupas Rename 2000*
http://www.irfanview.com/  IrfanView* (File-->Batch Conversion/Rename...)
http://www.publicspace.net/windows/BetterFileRename/ Better File Rename (Not Free)
http://www.123renamer.com/buy.htm File and MP3 Tag Renamer (Trial)


~~ Below is my own code from answer to "Rename Files Instantaneously":
http://www.experts-exchange.com/Operating_Systems/Win98/Q_21864152.html ~~
=================================================renlef+.bat
:: renlef+.bat
:: Prefix ADD utility for file names: Adds the specified prefix and delim (& optionally isolates delim by spaces) to all files that have specified extension
:: Doesn't perform the rename, but generates &  writes the commands to a bat file
:: If prefix+delim is already in the original name, then ignores the file unless doall=1
::
:: Arguments:
::   %1 - Prefix to add
::   %2 - Delimiter to add
::   %3 - Extension of file
::   %4 - Space - Set to 1 to add space to both sides of delim
::   %5 - Doall - See "If prefix+delim..." note above
::
:: v1.01  By Ravinder Singh ('wiz' on the quickmacros forum), May 26, 2006
::
::
:: if exists renlef+_.bat goto FILEEXISTS
@echo off
setlocal
set outfile=renlef+_
if exist "%outfile%.bat" del "%outfile%.bat"
if %1.==. (set /a exitcode=98&goto USAGE)
if %2.==. (set /a exitcode=98&goto USAGE)
set adn=%1&set delm=%2&set ext=%3&set space=%4&set doall=%5&&set count=0
if %doall%.==1. goto SIMPLE

for %%a in (*.%ext%) do (
if %space%.==1. (
     echo %%a| find "%adn% %delm% "
     if errorlevel 1 (set /a count+=1&echo ren "%%a" "%adn% %delm% %%a"  >> "%outfile%.bat" ))
if NOT %space%.==1. (
      echo %%a | find "%adn%%delm%"
     if errorlevel 1 (set /a count+=1&echo ren "%%a" "%adn%%delm%%%a" >> "%outfile%.bat"     ))
)
goto :DONE
:SIMPLE
::  separated routine here 'cause wasn't able to integrate 'cause of weird behaviour in msdos on Win2K
:: e.g. if you SET XX=YY, then echo "%XX%" doesn't give us XX's value within a FOR loop, but only on exit from loop
for %%a in (*.%ext%) do (
     set /a count+=1
     if %space%.==1. echo ren "%%a" "%adn% %delm% %%a"  >> "renlef+_.bat"
     if NOT %space%.==1.      echo ren "%%a" "%adn%%delm%%%a" >> "renlef+_.bat")

:DONE
if %count%==0 (
     echo No files found that match criteria.&echo.
     set /a exitcode=97
     goto usage
     )
type renlef+_.bat
echo.
echo type: %outfile%         To rename the above %count% files files! Or edit %outfile%.bat
goto :EOF

:USAGE
echo USAGE: %~nx0  WHAT-TO-APPEND-TO-LEFT   DELIMETER   EXTENSION  SPACE? ALL?
exit /B %exitcode%

:FILEEXISTS
echo renall.bat exists. (Check ^& ) Delete file first.
exit /B 99
====================================================renlef-.bat
:: renlef-.bat
::  - Prefix REMOVAL utility for file names: Cuts the specified prefix that precedes a space and/or the specified delimiters in a file name
:: As a precaution:
:: -- All rename commands are generated & then displayed on screen
:: -- All rename commands are written to a file which can be run  (after any optional or required user's edits)
::
:: Arguments:
::    %1 - Word to remove
::    %2 - Optional delimiters, in addition to the default space, that separate %1 from the part you want to keep
::    %3 - Extension of file
::
:: E.g. to remove initial "PART" from all files that start with "PART # ":
::     renlef- PART #
::
:: v1.01 By Ravinder Singh ('wiz' on the quickmacros forum), May 26, 2006
::
@echo off
setlocal
if %1.==. (set /a exitcode=98&goto usage)
set cut=%1&set delims=%2&set ext=%3&set outfile=renlef-_&set count=0
if exist "%outfile%.bat" del "%outfile%.bat"
::if not exist  "%outfile%.bat" set writeToFile=1
set writeToFile=1

:: Let user see and verify all rename commands before we execute them
for /f "usebackq delims=" %%i in (`dir /b %cut%*.%ext%`) do @call :TEST "%%i"

if %count%==0 (
     echo No files found that match criteria.&echo.
     set /a exitcode=97
     goto usage
     )
echo.
echo type: %outfile%           To rename the above %count% files! Or edit %outfile%.bat
goto :EOF
::1*

:TEST
set /a count+=1
set name=%1
FOR /f  "usebackq tokens=1,2,3 delims=%delims% " %%j IN (`echo %name%`) DO @set mycmd=ren %name% "%%k
echo %mycmd%
if %writeToFile%==1 echo %mycmd% >> %outfile%.bat
goto :EOF

:usage
echo usage: %~nx0   LEFT-TRIM-STRING   DELIMS    EXTENSION
exit /B %exitcode%

:: Other notes
::
:: original basic routine, with delimiters being "- "
::for /f "usebackq tokens=1,2,3  delims=- " %%i in (`dir /b %1*`) do echo ren "%%i - %%j" "%%j"
::
:: 1* -- Optional code, can use if you don't want to create %output%.bat
:: Now prompt whether or not to do the batch rename
set/p input=Enter y to execute the above commands, anything else to quit:  
if not %input%.==y. goto :EOF
for /f "usebackq delims=" %%i in (`dir /b %cut%*.%ext%`) do @call :RENAMEALL "%%i"
goto :EOF
:RENAMEALL
set name=%1
FOR /f  "usebackq tokens=1,2,3 delims=%delims% " %%j IN (`echo %name%`) DO ren %name% "%%k
goto :EOF

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-06-03 at 18:26:27ID21873735
Tags

rename

,

dos

,

files

Topic

MS DOS

Participating Experts
4
Points
500
Comments
22

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. JPG -> BMP
    I have my app to load some BMP's from resources . The problem is that BMP's are really large .. and my EXE is > 3MB . I wonder how could I load JPG and convert it to a HBITMAP or something .. Can anyone help me ? Thanks
  2. BMP to JPG
    Hi, I would like to know if in MFC is the libriry function that could take .bmp image/picture and makes it .jpg. Please, send exsact link/name of it. Regard, Gee

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GuruGaryPosted on 2006-06-03 at 23:08:45ID: 16826102

Looking at the code you posted here, I assume that "using pure DOS" means avoiding the use of external utilities, and that a Windows 2000 / XP command prompt is fine.  The following  code will prompt for "search" and "replacement" text, and echo the rename command for files in the current directory:

@echo off
setlocal

set /p Srch=Text in filename to find:
set /p Repl=Text to replace "%Srch%" with:
echo Searching for filenames containing "%Srch%" and replacing with "%Repl%" ...
for /f "tokens=*" %%a in ('dir /b *%Srch%*') do call :Replace "%%a"      
goto :EOF

:Replace
set x=%1
call set x=%%x:%Srch%=%Repl%%%
echo ren %1 %x%


As for the "free internet documentation of the ":~4%" feature", I couldn't find anything, but a brief description from my own experience is:
%variable:~start[,length]%
Using the environment variable ENV (as in set ENV=SomeTestText)
echo %ENV:~4%
would take the text in %ENV%, and echo starting at the 4th character to the end
echo %ENV:~4,2%
would take the text in %ENV%, and echo starting at the 4th character and outputting just 2 characters
echo %ENV:~-4,2%
would take the text in %ENV%, and echo starting at the 4th character from the end (because of the -) and outputting just 2 characters

Nice compilation of batch code.  I hope my input helps answer your most recent question.

 

by: SteveGTRPosted on 2006-06-04 at 20:56:18ID: 16830211

Could try this for NT2000+:

@echo off

setlocal enabledelayedexpansion

set fromMask=%~1
set toMask=%~2

if [%fromMask%]==[] echo Usage %0 fromMask [toMask]&goto :EOF

for /f "delims=" %%a in ('dir /b /a-d *.* 2^>NUL') do call :PROCESS "%%a"

goto :EOF

:PROCESS

set nameOnly=%~n1
set nameOnly=!nameOnly:%fromMask%=%toMask%!

if "%nameOnly%"=="" goto :EOF
if /i "%nameOnly%"=="%~n1" goto :EOF

echo ren %1 "%nameOnly%%~x1"

Note, I've disabled the rename for testing.

Good Luck,
Steve

 

by: dragon-itPosted on 2006-06-11 at 14:12:48ID: 16882021

Re: the %ENV~4% etc. try SET /? Gives detailed info.

Steve

 

by: callrsPosted on 2006-07-01 at 09:03:29ID: 17024137

Thanks for your answers.
Online documentation found at computerhope.com soon after this post, and proved helpful in various posts.
Will follow up here later this month.

Need to tend to a neglected garden yet...and to my own health. Body weight dropped over 10 pounds to 125 in past month. Been so busy at EE, getting by with tidbits of fruit, brown rice, mung beans, and vegetables. :-p

 

by: callrsPosted on 2006-07-21 at 20:32:30ID: 17158722

weary still -.-

 

by: callrsPosted on 2006-08-11 at 00:30:01ID: 17294270

Yikes. time passes so quickly. Not abandoning this. Had question for GuruGary but that will have to wait longer...

 

by: callrsPosted on 2006-09-01 at 18:11:03ID: 17440767

.

 

by: MohsanPosted on 2006-09-14 at 08:50:58ID: 17521794

dear read following book search substring it will give u the thing what u want

to improve ur skills in batch programming learn following text

A Modern Batch Programming Tutorial (Win 2k/XP)
Change the Look on This Site

<Text removed by AnnieMod -- the text was copy-paste from http://www.student.oulu.fi/~vtatila/batch_tutorial.html>

 

by: callrsPosted on 2006-09-14 at 09:38:04ID: 17522211

Mohsan, looks like a very nice tutorial, thank you.

But here's a tip: A link etc. is all-important to identify the source, and pasting some relevant material from the article can be better than copying in the whole thing.    ;)
And when the same entire long info is pasted across multiple threads, it needlessly balloons the forum; also, the author of the article may mind.

 

by: SteveGTRPosted on 2006-09-14 at 11:11:59ID: 17522950

I agree with callrs...

Here's the link:

http://www.student.oulu.fi/~vtatila/batch_tutorial.html

 

by: callrsPosted on 2006-09-14 at 11:18:54ID: 17523015

Link's can be had with a Google search of any phrase from the article. So should have let Mohsan come back to paste the link for practice sake lol

 

by: SteveGTRPosted on 2006-09-14 at 11:24:35ID: 17523075

:)

 

by: MohsanPosted on 2006-09-17 at 21:11:07ID: 17540846

Sorry dear.
next time i will post link.
www.student.oulu.fi/~vtatila/batch_tutorial.html

 

by: callrsPosted on 2006-10-17 at 01:01:10ID: 17745495

      * ¿ *
        °º°      

 

by: callrsPosted on 2006-10-17 at 02:04:38ID: 17745785

Too stressed to concentrate on this & other basics; so sending a heart beat for now.

 

by: SteveGTRPosted on 2006-10-17 at 05:35:28ID: 17746944

This is ridicules...

 

by: callrsPosted on 2006-11-08 at 04:42:31ID: 17897483



(Side note, of concern, not to bash: "start behaving as an adult" --> comment insults & is presumptuous of kids, who start off naturally loving giving inquisitive and faithful, and whom adults can learn mountains of wisdom from...adults not kids have made the pains we see in the world...)

In the spirit of helping upon which I embarked on this task -- spending, less for myself than for the world, not the stated 12 but double that time to find, categorize, test, edit, and fully credit a kaleidoscope of DOS rename routines --  I had hoped to spend several more hours to enhance the investment here before closing. In all honesty, question was asked not to ask it, but to find a way, in first days here at ee, to present the research to the programming community. But as this was something I 'selfishly' sought, I then got lost in solving others' multitude of issues at ee; a habit even in my own life of looking after others first: I often do for others what's delayed indefinitely for myself.

Computer's been my escape from hardships: recent major dental pain, looming critical housing crisis, renovation-company nightmare, malnutrition, neighborhood slander, people seeing my lack & harshly critiquing "you don't work", etc. Computer is where I can shut out practical and social stigmas and just go code or advise or help others...and I've done this for years free of charge even before ee, with countless expressions of thanks received.

No AnnieMod, I don't think the experts just love to lose their time; who does, least of all I who sees every moment as precious to be spent productively with a smile. I was simply buying time in a changed comic-relief sort of way despite what had happened that very month that has literally knocked me out since the 8th from an act of extreme insensitivity at ee, turning the computer screen -- a vital refuge -- into the very trap I sought escape from, with repercussions that have cost me and others great anguish and loss.

But closing thread as requested.

Sorry for the delay. I'd embarked on a multi-purpose file rename utility to post here (program to find and replace: prefix, suffix, middle, extension,...) the day of GuruGary's answer, but never finished the tests; right now however mental acuity is lacking to be able to complete it while other commitments await.


Cheers.

----
Mohsan, thanks for the apology & the commitment to the future. Hope you learn more MS-DOS as well : )

 

by: callrsPosted on 2006-11-15 at 23:59:59ID: 17954067

>>multi-purpose file rename utility
Possibly this week

 

by: callrsPosted on 2006-11-23 at 23:59:32ID: 18006281

Or not. Still embroiled in exhausting time-consuming three-months-long+ deluge from some at ee who (I've seen to grossly err yet) crassly brand others single-sidedly. Now another victim, one of high character to whom helping thoroughly, not points, has been paramount:  Recent case at CS I'm preparing input for; email if interested.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...