1.

Solve : Please help on this For loops?

Answer»

I am having a Text file (Certs.txt) which has paths of files like the one below
Certs.txt
C:\j2sdk1.4.2_13\jre\javaws\cacerts
C:\j2sdk1.4.2_13\jre\lib\security\cacerts
C:\oracle\ora92\jdk\jre\lib\security\cacerts
C:\Program Files\Java\j2re1.4.2\javaws\cacerts

My current code reads the path and copies all contents to folder CER_PEM.I then rename it into format (example.. cacerts3)required by using DELIM=. option.
The problem i face is since all files are of same name only the last file is PRESENT and renamed in CER_PEM folder. Rest all files are overwritten.But same works good for files that are NAMED different. I know the FOR LOOP needs to re-written,but cant get a breakthrough on it. Please help

Code Below

mkdir CER_PEM
FOR /F "delims=" %%a in (certs.txt) do (copy "%%a" c:\CER_PEM || CALL:sample)

:sample
set counter=0
FOR /F "tokens=1-2 delims=." %%a in ('dir CER_PEM /b') do CALL:FLY %%a %%b
:FLY
set /A counter=%counter%+1
REM echo %~1%counter%.%~2
rename c:\CER_PEM\%~1.%~2 %~1%counter%.%~2Code: [Select]md c:\cer_pem 2>nul
C:\batch>for /f "skip=2 tokens=1* delims=[]" %%a in ('find /v /n "" certs.txt') do copy "%%b" "c:\cer_pem\%%~nxb.%%a"

Quote

copy "%%a" c:\CER_PEM || CALL:sample
this line is if copy is unsuccessfull then call sample subroutine, you sure?

and you have to end every subroutine in the batch with this line "GOTO:eof", including your main sub. otherwise the code will just keep go on until end of line.


Discussion

No Comment Found