Run script on each file in directory

August 13, 2009 at 01:45:04
Specs: Windows XP, 2.793 GHz / 3574 MB
I currently have a batch file that chacks the contents of a file and replaces part of a text string (thanks to Machanix2Go)this works fine.
However, now I need to run this script on all files in a directory (different file names and file extensions)and it is important that I keep exactly the same file name and extension.
The script is as follows:

@ECHO OFF > d:\l\var\pmcli\ifc\CCS\jobs\tempfile & setLocal EnableDelayedExpansion

ECHO **CHANGING EXP CODE** >> d:\l\local\LogFiles\OldJobOut.log

FOR /f "tokens=* delims=" %%a in (d:\l\var\pmcli\ifc\CCS\jobs\bjobo) do (set str=%%a
SET head=!str:~0^,18!
IF !str:~18^,2! equ 20 (
SET new=!head!20SCDC1234567890
ECHO !new! >> d:\l\var\pmcli\ifc\CCS\jobs\tempfile
SET /a chgs+=1) else (echo !str! >> d:\l\var\pmcli\ifc\CCS\jobs\tempfile))

ECHO **EXP CODE NOW "SCDC1234567890"** >> d:\l\local\LogFiles\OldJobOut.log

As you see a temporary file is created but I cannot figure out a way to rename it as the original or run it on every file in the directory.
Thanks in advance for any help

See More: Run script on each file in directory

Report •

August 13, 2009 at 05:29:58
I'll give you a real quicky because my ISP is half dead.

Use another for loop to "wrap' your existing cade.

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


Report •
Related Solutions

Ask Question