Trancate the files in windows

August 30, 2011 at 12:02:44
Specs: Windows XP
Hi I have a requirement to truncate the files in windows.
Files are like
c_data_bin_file1.xml
c_data_bin_file2.xml
c_data_bin_file3.xml
.
.
.
I want to remove the initial part and make the file as
file1.xml
file2.xml
file3.xml
.
.
.
.
Is it possible using the batch file. please help asap

See More: Trancate the files in windows

Report •


#1
August 30, 2011 at 16:23:54
Yes, it is quite easy:

RENAME "C_DATA_BIN_FILE1.XML" FILE1.XML
RENAME "C_DATA_BIN_FILE2.XML" FILE2.XML
RENAME "C_DATA_BIN_FILE3.XML" FILE3.XML

Mouse could not be found. Click OK to continue.
What to do now?


Report •

#2
August 31, 2011 at 00:29:00
Thanks for your reply... but i have hundreds of file in sequence and i don't want to type rename command for all the files.. i want a batch program that should read the files in sequence and either rename or truncate the initial part...

Report •

#3
August 31, 2011 at 15:38:51
If it goes like 1, 2, 3, ... numbers for filenames, you could use something like this:

@ECHO OFF
SET /A CURNUM=1
ECHO Enter ending number for file:
SET ENDNUM=
SET /P ENDNUM=
SET /A ENDNUM=%ENDNUM%
:LOOP
RENAME "C_DATA_BIN_FILE%CURNUM%.XML" FILE%CURNUM%.XML
SET /A %CURNUM%+1
IF %CURNUM%==%ENDNUM% GOTO END
GOTO LOOP
:END
EXIT

Mouse could not be found. Click OK to continue.
What to do now?


Report •

Related Solutions

#4
September 1, 2011 at 10:38:40
Easier:
for %%a in (c_data_bin*.xml) do for /f "tokens=4 delims=_" %%b in ("%%a") do ren %%a %%b

How To Ask Questions The Smart Way


Report •


Ask Question