Solved

Help rename filename

Posted on 2003-10-31
2
3,832 Views
Last Modified: 2012-06-27
I'm trying to rename SF0310271145.CSV (SFyymmddhhmm.csv) to SISCR12mmddhhmm.csv in command prompt using 'rename' but it truncates the filename.

Here's what I enter at the prompt...

   ren SF03*.CSV SISCR12*.CSV


The result is...

   SISCR1271145.CSV

I tried this in NT4.0 and XP Pro with the same results.  Is there a undocumented switch for 'rename'.  I need to create a batch script that can do this for me automatically.  Please help.  TIA.
0
Comment
Question by:jperri
2 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 9661404
Try this:

@echo off

set filename=SF0310271145.CSV

ren %filename% SISCR12%filename:~4%

Good Luck,
Steve
0
 
LVL 5

Accepted Solution

by:
SethHoyt earned 140 total points
ID: 9661445
Here's a batch file that will rename all matching files:


@echo off

for %%i in (SF03*.CSV) do (set fname=%%i) & call :rename
goto :eof

:rename
ren %fname% SISCR12%fname:~4%
goto :eof


-Seth
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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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