0

I am new to batch files and need some help. I want to do the following.

I created a batch file that is looking for the folder "Recordings" within the file system and writes the results to a text file (results.txt). After that it is looking for the string "Directory" within the results. I want then merge every line from findstr (every path) with the execution-command of a tool I am using.

batchfile.bat:

@echo off
dir /S Recordings > C:\testing\results.txt
findstr Directory C:\testing\results.txt
PAUSE

The output looks like this:

C:\testing>batchfile.bat
 Directory of C:\testing\Scenarios\Default
 Directory of C:\testing\Scenarios\test1
Press any key to continue . . .

Now I want every line of this output to be merged with my execution-command:

tool.exe -parameter C:\testing\Scenarios\Default\Recordings
tool.exe -parameter C:\testing\Scenarios\test1\Recordings
1

I want every line of this output to be merged with my execution-command

Use the following batch file:

@echo off
setlocal
for /f "usebackq" %%i in (`dir /a:d /b /s ^| findstr "Recordings"`) do (
  tool.exe -parameter %%i
  )
endlocal

Further Reading

  • @Jimi Great. Do you need more help? If this answered your question, please don't forget to accept the answer by clicking the accept button (the tick ✓ button). – DavidPostill Jan 25 '18 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.