Solved

Rename filename

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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