Solved For /F /L using a single for loop?

June 25, 2012 at 13:24:01
Specs: Windows 7
How do I do for /f and /l both using a single for loop? I have to so some file operation for a specific count increasing dynamically. I am not sure if this is possible. Please let me know how to implement it. I am a newbie. Thanks!

See More: For /F /L using a single for loop?

Report •

✔ Best Answer
June 26, 2012 at 05:31:09
I'm not entirely sure what you're attempting to do, but I suspect it can be simplified to:
@REM Formatting the files
@echo off
SetLocal EnableDelayedExpansion
set FormatFile=TestFile
set FileLocation=\\tk5bimrcdevbld\Bak\Rigel_Test
FOR %%g in ("%FileLocation%\TestFile*.dat") Do (
  set fileName=%%~Ng
  echo GAWK -f %FormatFile%.AWK "%%g" ^> ^
    "%FileLocation%\!fileName:TestFile(=FIRevenuePeriodAwked(!.dat"
)
echo processing files finished
pause

EDIT: Fixed code
How To Ask Questions The Smart Way



#1
June 25, 2012 at 13:31:57
You can't. You can nest them, however.

How To Ask Questions The Smart Way


Report •

#2
June 25, 2012 at 14:09:33
I have this....It does the job but says 'ProcessFiles is not recognized as internal or external command' while executing the first FOR loop in which this is called.

@REM Formatting the files
@echo off
SetLocal EnableDelayedExpansion
set FormatFile=TestFile
set FileLocation=\\tk5bimrcdevbld\Bak\Rigel_Test
set i=0
FOR /f %%g in ('dir /b "%FileLocation%\*.dat"') Do (
set /a i=i+1
call ProcessFiles)

:ProcessFiles
FOR /L %%B IN (1,1,%i%) Do (echo GAWK -f %FormatFile%.AWK "%FileLocation%\TestFile(%%B).dat" ^> "%FileLocation%

\FIRevenuePeriodAwked(%%B).dat"
set /a i=i+1
)
echo processing files finished
pause


Report •

#3
June 25, 2012 at 20:08:15
when calling a "local" procedure in batch, you need the colon:
call :ProcessFiles

I may be wrong, but the logic in your script appears to be off the mark. I fail to see why you need the i-counter at all. The for /f loop ('dir /b *.dat') should handle all the files without having to use the counter. If you need the value from the filename for the revenueperiodawked file, you could get that using line two shown below. (Note that this line is not really a "loop". It will only execute once.)

FOR /f %%g in ('dir /b "%FileLocation%\*.dat"') Do (
for /f "tokens=2 delims=()" %%a in ("%%g") do set number=%%a
echo GAWK -f %FormatFile%.AWK "%FileLocation%\%%g^> "%FileLocation%
\FIRevenuePeriodAwked(!number!).dat"
)
:end

there are numerous ways to do what you want, but methinks you're trying to apply several approaches at once, and that, alas, won't work! (kind of like bureuocracies and legislation and designs by commitees.)


Report •

Related Solutions

#4
June 26, 2012 at 05:31:09
✔ Best Answer
I'm not entirely sure what you're attempting to do, but I suspect it can be simplified to:
@REM Formatting the files
@echo off
SetLocal EnableDelayedExpansion
set FormatFile=TestFile
set FileLocation=\\tk5bimrcdevbld\Bak\Rigel_Test
FOR %%g in ("%FileLocation%\TestFile*.dat") Do (
  set fileName=%%~Ng
  echo GAWK -f %FormatFile%.AWK "%%g" ^> ^
    "%FileLocation%\!fileName:TestFile(=FIRevenuePeriodAwked(!.dat"
)
echo processing files finished
pause

EDIT: Fixed code
How To Ask Questions The Smart Way


Report •

#5
June 26, 2012 at 11:51:38
I like that: "%FileLocation%\!fileName:TestFile(=FIRevenuePeriodAwked(!.dat"

but shouldn't the for loop, as your punctuation seems to imply (ie dbl quotes), be without the /f?


Report •

#6
June 26, 2012 at 12:47:34
I have no idea what you're talking about. You're obviously a crazy person. (Yes, it should have been.)

How To Ask Questions The Smart Way


Report •

Ask Question