Btc Sources
Btc Sources

Reputation: 2061

Use call inside a forfiles

I've a script where I want to call a function for each file in a directory. Using forfiles, I've been able to list them like:

forfiles /p "%myPath%" /c "cmd /c echo @path NAME @file"

Note: myPath is a path with spaces, so I had to put it inside "".

However, I need to use a function LaunchRun I've in my batch file, so I tried:

forfiles /p "%myPath%" /c "call:LaunchRun @path @file"

Where my function needs that two parameters. The problem is that I'm getting:

ERROR: El sistema no puede encontrar el archivo especificado.

Translanted:

Error: System can't find the specified file

Since every example I found did use /c option launching a new console, I trid that too, as I did with the echo one:

forfiles /p "%myPath%" /c "cmd /c call:LaunchRun @path @file"

But then I get:

Intento no válido de llamar una etiqueta por lotes fuera de un archivo de script por lotes.

Translated:

Invalid attempt to call batch label outside of a file batch script.

That appears cause I'm calling it in a new console.

What can I do to be able to call my function at the loop?

Thank you in advance

Upvotes: 4

Views: 2448

Answers (1)

Endoro
Endoro

Reputation: 37589

Just use a for-loop:

for /r "%myPath%" %%a in (*) do call:LaunchRun "%%~a" "%%~nxa"

Upvotes: 2

Related Questions