Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Recursively Rename

Posted on 2008-06-15
10
Medium Priority
?
2,770 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
ID: 21788789
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
ID: 21788822
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
ID: 21790332
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:mastermindg89
ID: 21791309
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
ID: 21791349
"web.config2234" is not included in mask --> *.config.*
0
 
LVL 8

Expert Comment

by:devil_himself
ID: 21791359
*.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
ID: 21791378
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 2000 total points
ID: 21791403

@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
ID: 21791527
Thanks for all the help and your patience.
0
 

Author Closing Comment

by:mastermindg89
ID: 31467355
Thanks again.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

877 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