Solved

Rename filename

Posted on 2013-10-24
5
248 Views
Last Modified: 2014-02-02
I need a DOS batch script that will rename multiple directories which will rename e.g

20131019300_brig120_database.bak to brig120_database.bak

Thanks
0
Comment
Question by:rakkad
  • 2
  • 2
5 Comments
 

Author Comment

by:rakkad
ID: 39599057
As per question, any help would be appreciated

Thanks
0
 
LVL 1

Expert Comment

by:DidUReboot
ID: 39599073
I know its not a batch script, but why reinvent the wheel. Try out Bulk Rename Utility. It will do exactly what you're wanting to do. Its a bit scary to look at the first time with all of its options, but you can click and change things before you save. Once you have it open and all your folders are highlighted in the main window, in the bottom right you will see a Remove (5) area. In there you can hit the up button next to "First n" to increase the amount of characters you would like to remove off the beginning. Or if they are all the same, you can enter in exactly what they all start with in the "Word" box. Once you're all done, you hit the "Rename" button in the bottom right corner.

Bulk Rename Utility: http://www.bulkrenameutility.co.uk/Download.php
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39599092
If the pattern is always just get rid of the first X characters, or upto the first _ then this is easy enough.  This will split it at the first _:

From cmd.exe prompt:

for /f "tokens=1* delims=_" %a in ('dir /b /a-d 20*.bak') do ECHO rename "%~a_%~b"  "%~b"

From batch file double up the %

@echo off
cd /d "c:\backup files"
for /f "tokens=1* delims=_" %%a in ('dir /b /a-d 20*.bak') do @ECHO rename "%%~a_%%~b"  "%%~b"

This does a directory listing of the current folder for all .bak files starting with 20 to leave out any other ones already renamed.  It then splits the filenames into %a and %b.  %a gets the filename before the first _. %b gets the rest of the line.  That is then used in the rename command.

This will just SHOW you the rename commands so you can see it is OK.  remove the word ECHO to actually carry out the rename commands.

Steve
0
 

Author Comment

by:rakkad
ID: 39827492
Thanks for the comment this worked
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39827517
Great.... always nice to get feedback quicker than 3 months and better than 'average'expected grade ...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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