I'm writing a cmd file that will loop through all the directories in a given directory and generate swagger code for each file in each directory. I cannot get the correct syntax for the 'for' loops.
cd C:\Users\Sora Teichman\Documents\APIJsonModels\models
for /D %%A in ("C:\Users\Sora Teichman\Documents\APIJsonModels\models\*") do (
set fileFolder=%cd%
echo %fileFolder%
for /F %%G in (fileFolder) do (
set filePath=%f
echo %filePath%
java -jar .\swagger-codegen-cli.jar generate -i filePath -l csharp-dotnet2 -o fileFolder
)
)
I'm getting 'in was unexpected at this time'
at the outer for loop. I tried using a variable for the folder path, I tried with the asterisk and without, I tried ('dir "C:\Users\Sora Teichman\Documents\APIJsonModels\models"')
.
The ss64 does not provide enough detail for my scenario.
What is the correct syntax for this?
I know that I need double %% for the parameters because this is in a .cmd file, there are many question online for this issue :).
For context, I am running this command file from a .csproj file using an <Exec Command="codeGenerator.cmd"/>
tag.
Edit: @Stephan pointed out that I needed to set my variables correctly, but now I need help with the inner loop. When I use the fileFolder
variable, the error I get is 'The system cannot find the file C:\Users\Sora.' It is getting stuck on the space in the folder path.