Solved

Save as file in a Dos Bat file

Posted on 2013-12-04
7
334 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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 …

803 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