Batch rename loop help

October 14, 2010 at 12:41:26
Specs: Windows XP
I have a directory of files (cs.#.csv) that I need to pass to a program one at a time, but my program can only except one input filename (cs.csv). After the program is done I need to rename the next file to the input filename and repeat those same steps until it has processed all the files in the directory.

Filenames in directory:

As an example I need my batch file to do the following:
a. Rename cs.1.csv to cs.csv (input filename for program I need to execute)
b. Run command to execute program
c. Rename cs.2.csv to cs.csv
d. Run command to execute program

@echo off & SetLocal Enableextensions & setLocal enabledelayedexpansion
for /f "tokens=* delims= " %%a in ('dir/b/s/a-d C:\EDI_Files\Outbound\Closeout\Split\cs.*.csv) do (
run program
rename file

Can anyone help?

See More: Batch rename loop help

Report •

October 14, 2010 at 14:23:14
@echo off
pushd C:\EDI_Files\Outbound\Closeout\Split
for /F "delims=" %%a in ('dir /B /S /A-D cs.*.csv') do (
  copy "%%a" cs.csv > nul
  program_name cs.csv
del cs.csv
:: End_Of_Batch

Report •
Related Solutions

Ask Question