Solved

Save as file in a Dos Bat file

Posted on 2013-12-04
7
314 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
Comment Utility
Thanks for letting me Know.  I believe a Dos solution would be the best bet.
0
 
LVL 17

Expert Comment

by:Lior Karasenti
Comment Utility
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
Comment Utility
Thanks.  This worked great
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
Comment Utility
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
Comment Utility
Erm, why the B grade?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now