We know this works and works well from the commnd-line... Ref. Using forfiles with multiple file types for search mask?
for %G in (fileone, filetwo) do forfiles /P D:\hold\logs /M *.%G.* /C "cmd /c echo @path"
What we want to do is to use these two file masks: fileone and filetwo to CALL to another FORFILES and with the doubled up %%G this is now in a batch script.. I would suppose we could probably do both of these operations at one time?
SET SOMELOGS=D:\hold\logs
for %%G in (fileone, filetwo) do forfiles /P %SOMELOGS% /M *.%%G.* /C "cmd /c ECHO @path & call :locate @path"
:locate
echo somepath %%1
FOR /f "tokens=1-9 delims=/: " %aa IN ('forfiles /P "%SOMELOGS%" /M %%1 /D -1 /C "cmd /c echo @file @fdate @ftime"') DO call :ZIP %%a %%b %%c %%d %%e %%f %%g
:ZIP
PAUSE
results are:
"D:\hold\logs\server.fileone.log.2013-12-14.a"
Invalid attempt to call batch label outside of batch script.
"D:\hold\logs\server.fileone.log.2013-12-15.a"
Invalid attempt to call batch label outside of batch script.
"D:\hold\logs\server.fileone.log.2013-12-15.b"
Invalid attempt to call batch label outside of batch script.
"D:\hold\logs\server.fileone.log.2013-12-16.a"
Invalid attempt to call batch label outside of batch script.
This does not seem to work either.. Cannot use: /c more than one time... Ref..nested forfiles: path and extension filter
SET SOMELOGS=D:\hold\logs
for %%G in (fileone, filetwo) do forfiles /p %SOMELOGS% /m *.%%G.* "forfiles /p @path /M %%1 /D -1 /C "cmd /c echo @file @fdate @ftime"') DO call :ZIP %%a %%b %%c %%d %%e %%f %%g
:ZIP
PAUSE
Your FORFILES command launches a new CMD.EXE process, from which you attempt to call a subroutine within the originating batch process. You can't do that - the child process cannot access the originating one.
Instead, you can execute the same batch file with an additional parameter, (CALL isn't needed in this case), and add an IF at the top to detect the additional parameter and GOTO the subroutine.
Note - you are missing EXIT /B
in a couple places - you don't want to fall into the following subroutine!
@echo off
if "%~1" equ ":locate" goto locate
SET SOMELOGS=D:\hold\logs
for %%G in (fileone, filetwo) do forfiles /P %SOMELOGS% /M *.%%G.* /C "cmd /c ECHO @path & 0x22%~f00x22 :locate @path"
exit /b
:locate
shift /1
echo somepath %%1
FOR /f "tokens=1-9 delims=/: " %a IN ('forfiles /P "%SOMELOGS%" /M %%1 /D -1 /C "cmd /c echo @file @fdate @ftime"') DO call :ZIP %%a %%b %%c %%d %%e %%f %%g
exit /b
:ZIP
PAUSE
exit /b
But I think there is a better way. You can handle the first FORFILES the same way you handled the second one, using an extra FOR /F.
@echo off
if "%~1" equ ":locate" goto locate
SET SOMELOGS=D:\hold\logs
for %%G in (fileone, filetwo) do for /f "delims=" %%F in (
'forfiles /P %SOMELOGS% /M *.%%G.* /C "cmd /c ECHO @path"'
) do (
echo %%F
call :locate %%F
)
exit /b
:locate
echo somepath %%1
FOR /f "tokens=1-9 delims=/: " %a IN (
'forfiles /P "%SOMELOGS%" /M %%1 /D -1 /C "cmd /c echo @file @fdate @ftime"'
) DO call :ZIP %%a %%b %%c %%d %%e %%f %%g
exit /b
:ZIP
PAUSE
exit /b
Finally, I don't understand why you need any subroutines, since you can put multiple commands within a parenthesized block of code. I also don't understand why you need two levels of FORFILES. It seems to me like the code you have written so far can be accomplished with a single FORFILES.