Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

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
0
jedrtd
Asked:
jedrtd
  • 5
  • 4
  • 4
  • +2
1 Solution
 
sirbountyCommented:
I think we need further description here please...this is too vague (for me anyway)...
0
 
DanielWillmottCommented:
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

Open in new window

0
 
jedrtdAuthor Commented:
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\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\recip1756300.pcl"  -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

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,  
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DanielWillmottCommented:
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.

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

Open in new window

0
 
segurahCommented:
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\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:\ReCompose\PBGC\merge\printer\out_merge.vpf C:\ReCompose\PBGC\merge\printer\%1  
------ END FILE CONVERT.BAT ---------------
0
 
jedrtdAuthor Commented:
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:\
0
 
segurahCommented:
Put the 2 bat's in the same folder. (where ever yo wish)
0
 
jedrtdAuthor Commented:
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

0
 
segurahCommented:
The scripts create c:\recompose/pbgc/merge/spool/merge.vpf?
Also creates C:\ReCompose\PBGC\merge\printer/out_merge.vpf?(I think that here there is a bad slash, should be C:\ReCompose\PBGC\merge\printer\out_merge.vpf)
0
 
DanielWillmottCommented:
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\printer\out_merge.vpf %1
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 

Open in new window

0
 
jedrtdAuthor Commented:
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
0
 
DanielWillmottCommented:
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/reskit/y2kfix/x86/forfiles.exe
0
 
AmazingTechCommented:
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"
)

Open in new window

0
 
segurahCommented:
Do you correct the slash of the script?
0
 
jedrtdAuthor Commented:
thanks this work
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now