0

I have below cmd commands, when I run these in a batch file it doesn't execute as the command prompt terminates. But when I run these one by one manually it executes.

CD /d o:\database\UK
dir *LWRKF03* *NCOM* *DTP* *LLIQ01* *LCOG01* *LCIMS02* *LCLS01* *LOLYM* *LCHUB01* *ISD* *PUKODYS01* *PUKHSSS02* /s /t:c | findstr "%date%">C:\Users\43874210\Desktop\UK\FoundFiles.TXT
for /f "tokens=5 delims= " %i in ('"dir *LWRKF03* *NCOM* *DTP* *LLIQ01* *LCOG01* *LCIMS02* *LCLS01* /s /t:c | findstr "%date%""') do copy "%i" C:\Users\43874210\Desktop\UK
for /f "tokens=5 delims= " %i in ('"dir *LWRKF03* /s /t:c | findstr "%date%""') do copy "%i" X:
for /f "tokens=5 delims= " %i in ('"dir *NCOM* /s /t:c | findstr "%date%""') do copy "%i" W:
for /f "tokens=5 delims= " %i in ('"dir *DTP* /s /t:c | findstr "%date%""') do copy "%i" T:
for /f "tokens=5 delims= " %i in ('"dir *LLIQ01* *LCOG01* *PUKODYS01* *PUKHSSS02* /s /t:c | findstr "%date%""') do copy "%i" Q:
for /f "tokens=5 delims= " %i in ('"dir *LCIMS02* *LCLS01* /s /t:c | findstr "%date%""') do copy "%i" S:
for /f "tokens=5 delims= " %i in ('"dir *LOLYM* /s /t:c | findstr "%date%""') do copy "%i" R:
for /f "tokens=5 delims= " %i in ('"dir *LCHUB01* *ISD* /s /t:c | findstr "%date%""') do copy "%i" H:
4
  • 3
    within batchfiles, you have to use %%i instead of %i (described in for /?) Commented Jan 12, 2016 at 13:20
  • @Stephan you should turn this into answer. Commented Jan 12, 2016 at 13:23
  • @Christian.K done. Had to check some other quirks first. Commented Jan 12, 2016 at 13:43
  • You say command prompt terminates, so I guess you are running the batch file by double-clicking; you should open a new command prompt (cmd) window and run the batch file by typing its path into it (enclosed in ""), so you could see any error messages... Commented Jan 13, 2016 at 0:59

1 Answer 1

3

within batchfiles, you have to use %%i instead of %i (described in for /?)

example line:

for /f "tokens=5 delims= " %%i in ('dir *LWRKF03* *NCOM* *DTP* *LLIQ01* *LCOG01* *LCIMS02* *LCLS01* /a-d /s /t:c ^| findstr "%date%"') do copy "%%i" C:\Users\43874210\Desktop\UK

(I also corrected the syntax of in (....) and added dir parameter /a-d to exclude directories)

By the way - for me it's Tokens=4

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

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.