5

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?

JacobSM1984
  • 61
  • 1
  • 1
  • 4
  • If you include a link to the image we can edit it in for you. – Zong May 15 '14 at 14:45
  • `c:test_backup_folder` is a relative path that points to a folder under the current directory and obviously depending of what the current directory is the target of the copy will vary. Have you tried with an absolute path, something like `c:\somewhere\test_backup_folder`? – MC ND May 15 '14 at 15:04
  • Hey guys. Figured it out thanks to good old Reddit. No need for reply. Thanks :) – JacobSM1984 May 15 '14 at 15:14

5 Answers5

8

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
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • 1
    I figured it out thanks to the fine folks at Reddit. The syntax I used was: xcopy "\\My_Server_IP\SharedDrive\Folder\*" "C:\Test_Folder" /D /E /C /I /H /Y – JacobSM1984 May 15 '14 at 15:43
  • 7
    Your question said nothing about recursive copying, why would you expect to get a working solution when you don't provide accurate details? – foxidrive May 18 '14 at 16:42
3

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
user353gre3
  • 2,747
  • 4
  • 24
  • 27
Hasan
  • 31
  • 1
1

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...

Community
  • 1
  • 1
Markus
  • 3,225
  • 6
  • 35
  • 47
1

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"
manish kumar
  • 4,412
  • 4
  • 34
  • 51
1

To recursively copy files and subfolders from a directory use this:

md TEST_BACKUP_FOLDER
Robocopy "\\My_Servers_IP\Shared Drive\FolderName\*" TEST_BACKUP_FOLDER /E