Solved

Save as file in a Dos Bat file

Posted on 2013-12-04
7
342 Views
Last Modified: 2013-12-06
I have files being sent to my C:\temp directory.  Each file has the date added to it.

Example: ABNAVWH_12/05/2013.CSV   I would like to have it renamed to only ABNAVWH.CSV

Meaning I need the date striped away from the file.

I have multiple files and so far I have been doing this manually.  Is there a easier way to handle this?
0
Comment
Question by:ICTIndika
  • 2
  • 2
7 Comments
 

Author Comment

by:ICTIndika
ID: 39697455
Thanks for letting me Know.  I believe a Dos solution would be the best bet.
0
 
LVL 17

Expert Comment

by:Lior Karasenti
ID: 39697663
This script should do:
@echo off
cd /d "C:\Temp"
for /f "delims=_ tokens=1,*" %%a in ('dir /b /aa') do ren "%%a_%%b" "%%~na%%~xb"
goto :eof

Open in new window

0
 

Author Comment

by:ICTIndika
ID: 39697677
Thanks.  This worked great
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39700686
Aside from not being able to have / in the filename you can do it much simpler using just this:

ren *.csv ???????.csv

And it will rename to the first 7 chars worth of the filename

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39702774
Erm, why the B grade?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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