Behavior of xcopy when moving files on a network drive
Solution 1
To answer your question: xcopy would read all the files from the server to the host machine and send them all back to the network drive.
Solution 2
If there's an "archive" sub-directory, then the "cd" command will be successful at changing the current working directory.
The final "xcopy" command will copy only the contents of the current working directory to a sub-directory called "backup" that is relative to the current working directory (if that sub-directory doesn't exist, then xcopy may prompt you to confirm if you wish to have it created automatically, or it might even ask you if you wish to create a directory or a file).
(This all assumes, of course, that you have read/write access to the network drive Y: and that the mapping to drive Y: was successful.)
Related videos on Youtube
MPelletier
Developer with 8 years experience. I work with J, C, C++, C#, SQLite, MySQL, VBA, and a bunch of other odds and ends. On Twitter: @MPProg
Updated on September 18, 2022Comments
-
MPelletier over 1 year
Using a batch file, suppose a directory on a network machine, mapped to a drive with
net use
.net use \\"server name"\"share name" y:
Then from that directory
y: cd archive
An
xcopy
to another location on that drive.xcopy *.* backup\
What behaviour would
xcopy
take? Would a temporary copy of*.*
be sent to the host machine (the one on which the batch is started) only to be sent back to the destination directory, or would the copy be effected solely on the network drive? -
Randolf Richardson almost 13 yearsA better approach would be to copy to specific destinations instead of assuming that all the preceding commands were successful. For example: XCOPY "\\server name\share name\archive*.*" "\\server name\share name\archive\backup\"
-
MPelletier almost 13 yearsGood note. But as @bubu noted, there would be a temporary copy made to the host even with full paths, correct?
-
MPelletier almost 13 yearsAs a complementary question, would it be possible to do the copy entirely remotely, that is, to not bring the files to the host temporarily?
-
MPelletier almost 13 yearsOther than by starting a batch file on the server, I should say.
-
Randolf Richardson almost 13 years@MPelletier: XCOPY stores data in RAM (locally) before writing it. If the source and destination are on the same server, it doesn't matter, the data will still be transferred over-the-wire both ways. Novell had similar a tool called NCOPY which would instruct a NetWare server to copy data without sending it over the wire to/from the client (to conserve network bandwidth), and it could copy data much faster as a result. To realize the same effect, you'll probably just need to run the XCOPY command server-side.
-
Hans Kilian almost 13 yearsyou may want to try psexec... it's similar to starting a batch file on the server, but... technet.microsoft.com/en-us/sysinternals/bb897553.aspx
-
Thomas over 12 yearsDoes anyone know if Robocopy uses this same behavior?