[batch-file] Using a batch to copy from network drive to C: or D: drive

I am having issues executing a batch file that will copy files from a mapped network drive to a local drive.

Here is the batch code I'm using (it's just in a low level folder at the moment as I don't wanna execute commands in a production environment until I have everything perfect).

echo off
cls

echo Would you like to do a backup?

pause

copy "\\My_Servers_IP\Shared Drive\FolderName\*" C:TEST_BACKUP_FOLDER

pause

And I also tried:

echo off
cls

echo Would you like to do a backup?
pause

copy "\\My_Servers_Name\Shared Drive\FolderName\*" C:TEST_BACKUP_FOLDER

pause

Neither of the above commands will copy the files to C:TEST_BACKUP_FOLDER when I request it to do so, but if I use the same exact syntax but make a copy request from a local drive it works no problem with this syntax and goes directly into the above folder with no issues.

The strangest part is that the cmd output even shows the files I want copied are even recognized in the command line and at the end it says “1 files copied” but nothing copies over to that folder. So I know I have the copy request destination correct because it even recognises which files are in the folder and the names show up. And as I said the destination in C: is also correct because when I use that address on the local PC they copy to that folder every time. It's obviously something to do with the network drive. At first I thought maybe it was a permission issue but the folder I'm now trying on is a Shared mapped drive that anyone in the company can access and has r/w privilges to. Why such problems on a public shared drive?

Could you offer any further suggestions?

This question is related to batch-file scripting cmd copy

The answer is


Just do the following change

echo off
cls

echo Would you like to do a backup?

pause

copy "\\My_Servers_IP\Shared Drive\FolderName\*" C:\TEST_BACKUP_FOLDER

pause

This might be due to a security check. This thread might help you.

There are two suggestions: one with pushd and one with a registry change. I'd suggest to use the first one...


Most importantly you need to mount the drive

net use z: \\yourserver\sharename

Of course, you need to make sure that the account the batch file runs under has permission to access the share. If you are doing this by using a Scheduled Task, you can choose the account by selecting the task, then:

  • right click Properties
  • click on General tab
  • change account under

"When running the task, use the following user account:" That's on Windows 7, it might be slightly different on different versions of Windows.

Then run your batch script with the following changes

copy "z:\FolderName" "C:\TEST_BACKUP_FOLDER"

You are copying all files to a single file called TEST_BACKUP_FOLDER

try this:

md TEST_BACKUP_FOLDER
copy "\\My_Servers_IP\Shared Drive\FolderName\*" TEST_BACKUP_FOLDER

Examples related to batch-file

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH Can´t run .bat file under windows 10 Execute a batch file on a remote PC using a batch file on local PC Windows batch - concatenate multiple text files into one How do I create a shortcut via command-line in Windows? Getting Error:JRE_HOME variable is not defined correctly when trying to run startup.bat of Apache-Tomcat Curl not recognized as an internal or external command, operable program or batch file Best way to script remote SSH commands in Batch (Windows)

Examples related to scripting

What does `set -x` do? Creating an array from a text file in Bash Windows batch - concatenate multiple text files into one Raise error in a Bash script How do I assign a null value to a variable in PowerShell? Difference between ${} and $() in Bash Using a batch to copy from network drive to C: or D: drive Check if a string matches a regex in Bash script How to run a script at a certain time on Linux? How to make an "alias" for a long path?

Examples related to cmd

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH VSCode Change Default Terminal How to install pandas from pip on windows cmd? 'ls' in CMD on Windows is not recognized Command to run a .bat file VMware Workstation and Device/Credential Guard are not compatible How do I kill the process currently using a port on localhost in Windows? how to run python files in windows command prompt?

Examples related to copy

Copying files to a container with Docker Compose Copy filtered data to another sheet using VBA Copy output of a JavaScript variable to the clipboard Dockerfile copy keep subdirectory structure Using a batch to copy from network drive to C: or D: drive Copying HTML code in Google Chrome's inspect element What is the difference between `sorted(list)` vs `list.sort()`? How to export all data from table to an insertable sql format? scp copy directory to another server with private key auth How to properly -filter multiple strings in a PowerShell copy script