jedrtd
asked on
bat file that loops and renames
I need a bat file that loops in a director of files, read the files run 2 comand line process rename the file, read the next .........
I have written some very simple and basic bat file and dont know how to do a loop. I have a bat file that will do 1 file but need the code to loop.
thanks
I have written some very simple and basic bat file and dont know how to do a loop. I have a bat file that will do 1 file but need the code to loop.
thanks
I think we need further description here please...this is too vague (for me anyway)...
I'm not sure the details of what you are trying to do, but you can use the forfiles command to run through a directory and perform commands on the files...
forfiles /p <DIRECTORY> /c "CMD /C ren @FILE @FILE.old"
for example:
forfiles /p C:\DATA /c "CMD /C ren @FILE @FILE.old" will go through the c:\data directory and rename each file to it's filename + .old
ASKER
I have a director of 60 files recip1456300.pcl, recip1456305.pcl, recip1456986.pcl ..... up to 100 files (all file *.pcl).
I have 2 command lines that must be run for each file,
c:\bowe_group\prntmgmt\rec ompose\sha red\bin\go .exe techpcl -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_grou p\prntmgmt \recompose \shared" -i "C:\ReCompose\PBGC\merge\s pool\recip 1756300.pc l" -o "c:\recompose/pbgc/merge/s pool/merge .vpf" -f C:\ReCompose\PBGC\merge\sp ool\techpc l.tab -E opMessLang=us
c:\bowe_group\prntmgmt\rec ompose\sha red\bin\go .exe c:\recompose/pbgc/merge/pr ogram/merg e -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_grou p\prntmgmt \recompose \shared" -V RMK_VPF_IN="c:\recompose/p bgc/merge/ spool/merg e.vpf" -V RMK_VPF_OUT="C:\ReCompose\ PBGC\merge \printer/o ut_merge.v pf" -V RMK_CFI=merge.cfi -S abrpnt1 -P 44965 -E opMessLang=us
then rename the out_merge.vpf to 1756300.pcl (this file is in a different directory).
so it need to do this for all *.pcl in this directory
thanks for any help,
I have 2 command lines that must be run for each file,
c:\bowe_group\prntmgmt\rec
c:\bowe_group\prntmgmt\rec
then rename the out_merge.vpf to 1756300.pcl (this file is in a different directory).
so it need to do this for all *.pcl in this directory
thanks for any help,
I would definately look through this carefully and do this in a test area first. There is no way I could test this myself.
Below are two batch files. One is called update.bat which recurses through all of the .pcl files, calling _upd.bat for each file. The _upd.bat file performs the two commands and then moves the resultant out_merge.vpf file to a c:\final\ directory.
You can change the c:\final directory to something else of course, but the directory must exist before this is run.
Below are two batch files. One is called update.bat which recurses through all of the .pcl files, calling _upd.bat for each file. The _upd.bat file performs the two commands and then moves the resultant out_merge.vpf file to a c:\final\ directory.
You can change the c:\final directory to something else of course, but the directory must exist before this is run.
update.bat file
---------------
forfiles /p C:\ReComp~1\PBGC\merge\spool\ /m *.pcl /c "CMD /C _upd.bat @FILE"
_upd.bat file
---------------
c:\bowe_group\prntmgmt\recompose\shared\bin\go.exe techpcl -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_group\prntmgmt\recompose\shared" -i "C:\ReCompose\PBGC\merge\spool\%1" -o "c:\recompose/pbgc/merge/spool/merge.vpf" -f C:\ReCompose\PBGC\merge\spool\techpcl.tab -E opMessLang=us
c:\bowe_group\prntmgmt\recompose\shared\bin\go.exe c:\recompose/pbgc/merge/program/merge -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_group\prntmgmt\recompose\shared" -V RMK_VPF_IN="c:\recompose/pbgc/merge/spool/merge.vpf" -V RMK_VPF_OUT="C:\ReCompose\PBGC\merge\printer\out_merge.vpf" -V RMK_CFI=merge.cfi -S abrpnt1 -P 44965 -E opMessLang=us
move C:\ReComp~1\PBGC\merge\printer\out_merge.vpf c:\final\%1
Create this 2 files .. then it's done....
----- BEGIN FILE DO.BAT -----------
@echo off
for /f %%a IN ('dir /b *.pcl') do CONVERT.BAT %%a
----- END FILE DO.BAT ------------
----- BEGIN FILE CONVERT .BAT --------
@echo off
c:\bowe_group\prntmgmt\rec ompose\sha red\bin\go .exe techpcl -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_grou p\prntmgmt \recompose \shared" -i "C:\ReCompose\PBGC\merge\s pool\%1" -o "c:\recompose/pbgc/merge/s pool/merge .vpf" -f C:\ReCompose\PBGC\merge\sp ool\techpc l.tab -E opMessLang=us
c:\bowe_group\prntmgmt\rec ompose\sha red\bin\go .exe c:\recompose/pbgc/merge/pr ogram/merg e -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_grou p\prntmgmt \recompose \shared" -V RMK_VPF_IN="c:\recompose/p bgc/merge/ spool/merg e.vpf" -V RMK_VPF_OUT="C:\ReCompose\ PBGC\merge \printer/o ut_merge.v pf" -V RMK_CFI=merge.cfi -S abrpnt1 -P 44965 -E opMessLang=us
ren C:\ReCompose\PBGC\merge\pr inter\out_ merge.vpf C:\ReCompose\PBGC\merge\pr inter\%1
------ END FILE CONVERT.BAT ---------------
----- BEGIN FILE DO.BAT -----------
@echo off
for /f %%a IN ('dir /b *.pcl') do CONVERT.BAT %%a
----- END FILE DO.BAT ------------
----- BEGIN FILE CONVERT .BAT --------
@echo off
c:\bowe_group\prntmgmt\rec
c:\bowe_group\prntmgmt\rec
ren C:\ReCompose\PBGC\merge\pr
------ END FILE CONVERT.BAT ---------------
ASKER
I tried the do.bat, convert.bat, but I'm getting
convert.bat recip1756305.pcl
cannot found file specified
for each file
I put these bat file in the spool directory, is that where they should be or should I put them in c:\
convert.bat recip1756305.pcl
cannot found file specified
for each file
I put these bat file in the spool directory, is that where they should be or should I put them in c:\
Put the 2 bat's in the same folder. (where ever yo wish)
ASKER
it look like it is doing the 1st command in the convert.bat I can see the merge.vpf file changing size and when I display diff info. But I'm not getting anything in the printer file at all. get file not specifie
The scripts create c:\recompose/pbgc/merge/sp ool/merge. vpf?
Also creates C:\ReCompose\PBGC\merge\pr inter/out_ merge.vpf? (I think that here there is a bad slash, should be C:\ReCompose\PBGC\merge\pr inter\out_ merge.vpf)
Also creates C:\ReCompose\PBGC\merge\pr
Did the script I posted last night not work? It seems to work for me.
One note: you can change the last line to:
ren C:\ReComp~1\PBGC\merge\pri nter\out_m erge.vpf %1
to put the renamed files in the printer directory
One note: you can change the last line to:
ren C:\ReComp~1\PBGC\merge\pri
to put the renamed files in the printer directory
update.bat file
---------------
forfiles /p C:\ReComp~1\PBGC\merge\spool\ /m *.pcl /c "CMD /C _upd.bat @FILE"
_upd.bat file
---------------
c:\bowe_group\prntmgmt\recompose\shared\bin\go.exe techpcl -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_group\prntmgmt\recompose\shared" -i "C:\ReCompose\PBGC\merge\spool\%1" -o "c:\recompose/pbgc/merge/spool/merge.vpf" -f C:\ReCompose\PBGC\merge\spool\techpcl.tab -E opMessLang=us
c:\bowe_group\prntmgmt\recompose\shared\bin\go.exe c:\recompose/pbgc/merge/program/merge -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="c:\bowe_group\prntmgmt\recompose\shared" -V RMK_VPF_IN="c:\recompose/pbgc/merge/spool/merge.vpf" -V RMK_VPF_OUT="C:\ReCompose\PBGC\merge\printer\out_merge.vpf" -V RMK_CFI=merge.cfi -S abrpnt1 -P 44965 -E opMessLang=us
ren C:\ReComp~1\PBGC\merge\printer\out_merge.vpf %1
ASKER
I did try it, but it gave me error
forfile not recognized as an internal or externa operable program or batch file
so I tried the next option
forfile not recognized as an internal or externa operable program or batch file
so I tried the next option
Ah...forfiles is installed by default with Windows 2003 and above. I'm assuming you're using windows 2000 or XP? If so, you can get forfiles from here: ftp://ftp.microsoft.com/re skit/y2kfi x/x86/forf iles.exe
Give this a try.
SETLOCAL ENABLEDELAYEDEXPANSION
Set InstallDir=c:\bowe_group\prntmgmt\recompose\shared
Set EXEFile=\bin\go.exe
Set MergeDir=C:\ReCompose\PBGC\merge
for /f "tokens=*" %%a in ('dir /a-d /b "%MergeDir%\*.pcl"') do (
Set NewFilename=%%~na
Set NewFilename=!NewFilename:~5!
"%InstallDir%\%EXEFile%" techpcl -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="%InstallDir%" -i "%MergeDir%\spool\%%a" -o "%MergeDir%\spool\merge.vpf" -f %MergeDir%\spool\techpcl.tab -E opMessLang=us
"%InstallDir%\%EXEFile%" %MergeDir%\program\merge -E opWD="c:\recompose" -E opFam="pbgc" -E opAppli="merge" -E opInstallDir="%InstallDir%" -V RMK_VPF_IN="%MergeDir%\spool\merge.vpf" -V RMK_VPF_OUT="%MergeDir%\printer\out_merge.vpf" -V RMK_CFI=merge.cfi -S abrpnt1 -P 44965 -E opMessLang=us
REN "%MergeDir%\printer\out_merge.vpf" "!NewFilename!.pcl"
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks this work