0

I've written a batch script which processes a series of files, but now I want it to copy the output files to the correct directory.

for %%f in (closecaption_*.txt) do (
  "%cd%\bin\captioncompiler.exe" "%cd%\%%f"
  copy /y "%cd%\%%f" "Z:\Users\jbzdarkid\"
)
pause

Currently, this script will copy all of the .txt files into my home directory. However, I want it to move the .dat files (the output) into my directory instead. Ideally, it would only move the new .dat files, i.e. the ones that have just been processed.

I would like to be able to do something like this:

for %%f.txt in (closecaption_*.txt) do (
  "%cd%\bin\captioncompiler.exe" "%cd%\%%f.txt"
  copy /y "%cd%\%%f.dat" "Z:\Users\jbzdarkid\"
)
pause

however this does not work.

2 Answers 2

1
for %%f in (closecaption_*.txt) do (
  "%cd%\bin\captioncompiler.exe" "%cd%\%%f"
  copy /y "%cd%\%%~nf.dat" "Z:\Users\jbzdarkid\"
)
pause

should work, if my crystal ball is working correctly. It selects the name-par of %%f.

Some examples would have made the matter clearer.

Sign up to request clarification or add additional context in comments.

Comments

0

The following code should work:

for /f "tokens=1,2 delims=." %%f in ('dir /a-d /b "%cd%\closecaption_*.txt"') do (
    "%cd%\bin\captioncompiler.exe" "%cd%\%%f"
    copy /y "%cd%\%%f.dat" "Z:\Users\jbzdarkid\"
)
pause

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.