Solved

Rename filename

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 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