Solved

Save as file in a Dos Bat file

Posted on 2013-12-04
7
353 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
[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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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