[Solved] Use a batch file to rename files with a CVS

Score
0
Vote Up
February 4, 2012 at 22:44:50 Pacific
Specs: Windows XP

I'm working on making a batch that rename files base on cvs file. I will look in a input dir for a file containing the whats in the first part of the cvs, then move and change the name to what in the seconded part of the cvs.

so it should work like this...

Master.cvs
A3,09
33,72

the batch file would look in the C:\input for a file name A3.txt then when it finds it. the batch would move the A3.txt to C:\output with the new name of 09.txt

thanks for any help.


Jump to Best Answer ↓   Report •


#1
Vote Down
Score
0
Vote Up
February 5, 2012 at 06:57:55 Pacific

Best Answer

@echo off
for /F "tokens=1-2 delims=," %%a in (Master.csv) do (
  if exist "C:\input\%%a.txt" move "C:\input\%%a.txt" "C:\output\%%b.txt"
)


Reply ↓  Report •

#2
Vote Down
Score
0
Vote Up
February 5, 2012 at 07:22:00 Pacific

Thanks, but that only worked on the top line of cvs. can it loop through each line?


Reply ↓  Report •

#3
Vote Down
Score
0
Vote Up
February 5, 2012 at 07:53:41 Pacific

Are you sure?

I have a huge experience in For /F statements and do assure the code I posted browses the whole Master.csv file performing the if exist for each line inside.


Reply ↓  Report •

#4
Vote Down
Score
0
Vote Up
February 5, 2012 at 08:14:25 Pacific

that was my bad i was using some bad sample data..

Thanks so much.


Reply ↓  Report •

Reply to Message Icon Start New Discussion
Related Posts

« Create folder - partial f... [Solved] How Do I Check If a Progr... »