Solved

Recursively Rename

Posted on 2008-06-15
10
2,719 Views
Last Modified: 2010-04-21
I need a PURE DOS solution to rename files recursively based upon a mask:

*.config.*

Searching through the site I came across this code:

FOR /F "tokens=*" %A in ('dir /A:-D /S /B fid') DO REN "%A" fid.mrc

This works only if you need to rename one file recursively. I need to rename multiple files, in particular, files matching the above mask: *.config.*

I would also like to be able to add exclusions; for instance, .config, .xml, .dll. I would also like to be able to store the files renamed into a text file.

I need to add the extension .config to files matching this mask excluding files with extension .config, .xml, .dll, and so on. For example,

web.config            ------>    DO NOT RENAME   ---->   web.config
web.config.bak     ------>          RENAME           ---->   web.config.bak.config
web.config.7634   ------>          RENAME           ---->   web.config.7634.config
program.config.34 ------>          RENAME           ---->   program.config.34.config
program.config.dll  ------>    DO NOT RENAME   ---->   program.config.dll
0
Comment
Question by:mastermindg89
  • 5
  • 4
10 Comments
 
LVL 35

Expert Comment

by:torimar
Comment Utility
Please check out this freeware utility: http://www.brothersoft.com/lupas-rename-download-61151.html

If it should be capable to do what you need done, you can have it generate a .BAT file for use in a DOS environment.

Hope this helps.
0
 

Author Comment

by:mastermindg89
Comment Utility
I've tried Lupas and it is an impressive tool. However, it does not offer exclusions.

The mask *.config.* brings up all .config files and I don't want to rename these files just those with added extensions.
0
 
LVL 8

Expert Comment

by:devil_himself
Comment Utility
SCRIPT TEST

These Were The Files In Folder
==
web.config
web.config.bak
web.config.7634
program.config.34
program.config.dll
==

SCREEN OUTPUT OF SCRIPT
==
ren "C:\Source\program.config.34" "program.config.34.config"
ren "C:\Source\web.config.7634" "web.config.7634.config"
ren "C:\Source\web.config.bak" "web.config.bak.config"
==



@echo off

setlocal

set source=c:\source

set dest=c:\dest

set excludeExt=.config .xml .dll

pushd "%source%"

for /f "tokens=*" %%a in ('dir "*.config.*" /A:-D /S /B ^|findstr /I /E /V "%excludeExt%"') do echo ren "%%a" "%%~nxa.config"

Open in new window

0
 

Author Comment

by:mastermindg89
Comment Utility
The script works great. It lacks only one thing. There may be some files renamed like this:

web.config2234
web.configconfig.test

The script doesn't rename these, more than likely because of the .config in the extension.
0
 
LVL 8

Expert Comment

by:devil_himself
Comment Utility
"web.config2234" is not included in mask --> *.config.*
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 8

Expert Comment

by:devil_himself
Comment Utility
*.config* will solve all your problems
@echo off

setlocal

set source=c:\source

set dest=c:\dest

set excludeExt=.config .xml .dll

pushd "%source%"

for /f "tokens=*" %%a in ('dir "*.config*" /A:-D /S /B ^|findstr /I /E /V "%excludeExt%"') do echo ren "%%a" "%%~nxa.config"

Open in new window

0
 

Author Comment

by:mastermindg89
Comment Utility
I also altered the script to rename rather than print the rename commands. I need the files renamed as well as a list of the files renamed in a file.

so %dest% would be a text file and the script would do rename followed by an echo to the text file.
0
 
LVL 8

Accepted Solution

by:
devil_himself earned 500 total points
Comment Utility

@echo off

setlocal

set source=c:\source

set logfile=log.txt

set excludeExt=.config .xml .dll

pushd "%source%"

for /f "tokens=*" %%a in ('dir "*.config*" /A:-D /S /B ^|findstr /I /E /V "%excludeExt%"') do ren "%%a" "%%~nxa.config" & echo "%%a" --^> "%%~nxa.config" >> %logfile%

Open in new window

0
 

Author Comment

by:mastermindg89
Comment Utility
Thanks for all the help and your patience.
0
 

Author Closing Comment

by:mastermindg89
Comment Utility
Thanks again.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now