Computing.Net > Forums > Programming > Batch file for renaming files

Batch file for renaming files

Reply to Message Icon

Original Message
Name: Naveen
Date: June 7, 2007 at 00:53:18 Pacific
Subject: Batch file for renaming files
OS: Win XP
CPU/Ram: p4 1 GB
Model/Manufacturer: Intel
Comment:

Hi,
I require a simple batch file to run on cmd prompt which when run, would do a 'dir' on the current directory/specified directory and rename the files as follows:-

existing filename format - file_[1]_name.txt
required filename format - file_name.txt

I'm not aware of the syntax for windows, so if anyone could help :-)

Thanks


Naveen


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: June 7, 2007 at 01:15:38 Pacific
Reply: (edit)

@echo off > file_[1]_name.txt
setLocal EnableDelayedExpansion

for /f "tokens=1-3 delims=_" %%a in ('dir/b/a-d file_*.*') do (
echo ren %%a_%%b_%%c %%a_%%c
)



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file for renaming files

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge