Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rename filename

Posted on 2013-10-24
5
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

718 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