Solved

Rename filename

Posted on 2013-10-24
5
249 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
listing file names and path into notepad 3 61
DOSBox Keyboard 3 71
hosts.ini- can it be made to block all websites? 14 80
netsh interface ip show interface in Windows XP 4 118
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

14 Experts available now in Live!

Get 1:1 Help Now