0

I'd like to copy the contents of D:\Documents (a folder on a local hard-drive) to Z:\Documents (a folder mapped to a NAS device).

xcopy.exe D:\Documents Z:\Documents /d /s /y

  • /d - copies all Source files that are newer than existing Destination files
  • /s - copies directories and subdirectories, unless they are empty
  • /y - suppresses prompting to confirm that you want to overwrite an existing destination file.

Fails saying:

Access denied

Unable to create directory - Z:\Documents

It's worth noting that Z:\Documents already does exist (and should exist, I want to copy files new/newly modified files into the existing folder).

If I reverse the source and destination the command works as expected, so I know both of the paths are correct.

If I open a command prompt and attempt to create a new directory in Z:\ or create a new file inside of Z:\Documents I'm able to without issue, so I know I have write-access to the Z:\ drive.

Can anyone tell me what I'm doing wrong?

1
  • 1
    xcopy.exe D:\Documents\* Z:\Documents /d /s /y /r add the /r flag. Also are you running it in an admin shell. Also, is the Z:\ drive ntfs or fat? I've also read a bunch about xcopy not liking hidden files, maybe mess w that attribute.
    – Narzard
    Aug 12, 2019 at 3:07

1 Answer 1

1

I tried 3 actions to tackle this issue:

  1. use /R, Use this option to overwrite read-only files in destination. If you don't use this option when you want to overwrite a read-only file in destination, you'll be prompted with an "Access denied" message and the xcopy command will stop running.
  2. try use \\hostname\sharedfolder instead of the mapped label Z:\
  3. run as administrator, and make it clear if you are using administrator or other use to net the sharedfolder. Both OK for my environment.
1
  • 1
    Network drives exist in the user context. Running a script as a different user, or as administrator, is a different context and so you won't have the same mapped drives. Jul 9, 2020 at 3:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .