0

I have a PDF .COMInterop and C# Notes - Notes 1 to 10.pdf kept in the directory D:\Dropbox\Sample C# Notes

The folder Sample C# Notes also has some subfolders like 0001, 0002, 0003 and so on till 0100.

I am writing the following command in a batch file to copy the pdf from Sample C# Notes to all the subfolders inside it (0001, 0002, 0003...)

for /D %%x in (D:\Dropbox\Sample C# Notes\*.*) 
DO COPY D:\Dropbox\Sample C# Notes\.COMInterop and C# Notes - Notes 1 to 10.pdf %%x\.COMInterop and C# Notes - Notes 1 to 10.pdf

But it gives an error saying The system cannot find the file specified. Where am I going wrong?

4
  • 1
    Try to put double quotes around the filename : "D:\Dropbox\Sample C# Notes\.COMInterop and C# Notes - Notes 1 to 10.pdf" Commented Dec 21, 2018 at 14:22
  • I still get the same error for /D %%x in (D:\Dropbox\Sample C# Notes*.*) DO COPY "D:\Dropbox\Sample C# Notes\.COMInterop and C# Notes - Notes 1 to 10.pdf" %%x\".COMInterop and C# Notes - Notes 1 to 10.pdf" Commented Dec 21, 2018 at 14:34
  • And why do you think the folder in the parentheses does not need double quotes? Commented Dec 21, 2018 at 14:42
  • tried that too. says invalid syntax. Commented Dec 21, 2018 at 14:44

1 Answer 1

1

File/folder names with spaces always need to be double quoted.

for /D %%x in ("D:\Dropbox\Sample C# Notes\*") DO (
  COPY "D:\Dropbox\Sample C# Notes\.COMInterop and C# Notes - Notes 1 to 10.pdf" "%%x\"
)

or

PushD "D:\Dropbox\Sample C# Notes\"
for /D %%x in (*) DO (
    COPY ".COMInterop and C# Notes - Notes 1 to 10.pdf" "%%x\"
)
PopD
Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thanks a ton!

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.