Solved Rename Files in Batch Script

November 21, 2011 at 08:17:29
Specs: Windows Server 2008, 6-Core/4GB
I have several files in a windows directory that I need to rename. They are all named as filename_yyyymmdd.csv, with different filenames (filename1_yyyymmdd.csv, filename2_yyyymmdd.csv etc...) I need to be able to rename them to filename.csv. I can do simple commands, but scripts are not really my cup of tea. Please help!

See More: Rename Files in Batch Script

Report •

#1
November 21, 2011 at 11:02:24
✔ Best Answer
so basically you want to remove the yyyymmdd part ? if yes try this .

Not from a batch script but right from a cmd line.

--------------------------------------------------------------------------------------------
cd C:\windows\yourpath-to-files
for /f "tokens=1,2 delims=_" %a in ('dir /b *.csv') do ren %a* %a.csv
---------------------------------------------------------------------------------------------

do this on a test folder first before putting on real folders.

- Subhash
 Monthly giveaway -  Grab PC Safety Ebook


Report •

#2
November 21, 2011 at 11:11:08
Thanks so much for the reply!
It works great for all the files, except two files that have similar names:
I have one file named homedepot_yyyymmdd.csv and another named homedepot-canada_yyyymmdd.csv.
It seems to be removing the yyyymmdd from the canada file first and for then does a homedepot*.csv which gives it both the homedepot files.
Can you please suggest something that can take care of this?
Thanks again!

Report •

#3
November 21, 2011 at 11:44:12
if its just 2 files, you can rename it manually , isn't ? if you need to do this reoccurring, let me know will give you work-around

- Subhash
 Monthly giveaway -  Grab PC Safety Ebook


Report •
Related Solutions


Ask Question