I'm writing a small batch file to copy my C# project to another drive. I'm using XCOPY to copy an entire folder (We have some XP machines still, so robocopy isn't an option). However, when I run the batch file, it tells me that it cannot find the FILE specified (why it's looking for a file and not a folder I have no clue).

Here's my folder structure. I'd like to copy folder to the program\dst folder on the O drive.



My batchFile.bat contains the following line

XCOPY  ".\folder" "O:\program\dst" /E

When I run this, it says:

File Not Found - folder

even though it most definitely exists (as a folder, not a file).


I tried this, and it works for me. I'm guessing you've created a shortcut to the batch file, and the start directory isn't correct. If so, adding a cd command to the start of the batch file to change directory into src should fix it, or alternatively use an absolute path to folder instead of a relative one:

cd "C:\Whatever\src"
XCOPY ".\folder" "O:\program\dst" /E


XCOPY "C:\Whatever\src\folder" "O:\program\dst" /E
  • No shortcut, I'm running it directly, so I'm not sure why the relative path isn't working (as it is preferred to use relative path for my needs) – audiFanatic Jul 28 '14 at 19:14
  • @audiFanatic have you tried it with an absolute path? – Cocowalla Jul 28 '14 at 21:17
  • Yea, and it works. But absolute isn't the best solution for my needs unfortunately. – audiFanatic Jul 29 '14 at 1:09
  • @audiFanatic is creating a shortcut with the 'Start in' field set to the absolute path to 'src' a viable option for you? – Cocowalla Jul 29 '14 at 7:50
  • Well, the thing is I'm trying to move these files between computers over a shared drive, so I'm not sure that I can use an absolute path at all because I cannot guarantee that it'll be valid. – audiFanatic Jul 29 '14 at 12:35

In your script put the below command to the very beginnig of your CMD file:

echo "%cd%"

Then observe what this command produces.

If your "folder" directory's full path is "C:\ABC\folder" then echo "%cd%" command should yield the output "C:\ABC". However, if you see something different from this then your XCOPY command fires file not found error. This is normal because XCOPY cannot determine whether "folder" is directory or file and assume it is default to a file.


As other answers suggest, using .\folder starts from the current directory, while you want the batch file's location:

XCOPY  "%~dp0\folder" "O:\program\dst" /E

You could cd to the folder first, but this is more elegant IMO.

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.