Behavior of xcopy when moving files on a network drive

5,713

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

Share:
5,713

Related videos on Youtube

MPelletier
Author by

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, 2022

Comments

  • MPelletier
    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
    Randolf Richardson almost 13 years
    A 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
    MPelletier almost 13 years
    Good note. But as @bubu noted, there would be a temporary copy made to the host even with full paths, correct?
  • MPelletier
    MPelletier almost 13 years
    As 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
    MPelletier almost 13 years
    Other than by starting a batch file on the server, I should say.
  • Randolf Richardson
    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
    Hans Kilian almost 13 years
    you 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
    Thomas over 12 years
    Does anyone know if Robocopy uses this same behavior?