简体   繁体   中英

Move files to a network drive via batch script

I have a network drive and I'd like to move some files on it via the windows task scheduler however I have some trouble making the batch file.

start "" "C:\PATH_TO_7z\7za.exe" a -tzip D:\Backup.zip D:\*.xlsx
Pause
move "D:\Backup.zip" "\\HostName\ShareName"
Pause

The move command say that he cannot find the network name.

I've tried to use net use like

net use S: "\\HostName\ShareName"

And here it says error 67 and he still cannot find the network name too.

However I succeed to move files with the same command line when I use it from the CMD and not from a batch file (I tried to run batch file as admin too).

So my question is, how can I map this drive within the script and then move my files in the drive ?

EDIT: I did a bit of testing and found out that when I run a windows CMD as an admin net use does not see my network drive but when I run a CMD normally I did see the disk.

You are getting ERROR_BAD_NET_NAME . The correct pattern is \\\\HostName\\ShareName . If you can't remove the start command from the script, then add the /WAIT option to its command line. It's possible you are witnessing a race for access to the zip file.

This was failing for me and it was because the hostname is case sensitive. Hope this helps someone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM