2

I am trying to run a simple xcopy command at machine shutdown. When I execute the command via cmd , everything works as expected. However when I paste it in a batch file and try to run it , I encounter errors. Here is the command:

FOR /D %d in (*) DO xcopy /S /I /y /exclude:exclude.txt %d V:\SUBFOLDER\%d

The error I get is : "unexpected exclude.txt " I tried surrounding the file name with quote marks but it is didn't solve the issue. What am I doing wrong? Thank you for your help!

1 Answer 1

2

In a batch file, you need to use %%d rather than %d:

FOR /D %%d in (*) DO xcopy /S /I /y /exclude:exclude.txt %%d V:\SUBFOLDER\%%d

If you're serious about learning various Windows scripting tools, you can't go past Rob van der Woude's website. This covers a very wide range of subjects. You may also want to consider switching to Powershell since it's a great step up from the cmd.exe scripting language.

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

2 Comments

wow that was quick! Thanks a lot! Where can I find more infos about this?
@uaaron22, see the update for an excellent learning resource.

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.