Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a folder with several files and folders, including hidden files. This folder is stored on a server. I need a command-line script to copy this folder from the server to a specific location on a local machine. Note: it needs to overwrite the folder with the same name on the local machine.

I use the below script to do this, however, I am not seeing where the local folder is being overwritten by the folder on the server.

Script:

xcopy /s /z /y /r /h /g /e "\\xx.xx.xx.xx\A\B\C\" "C:\Users\%username%\AppData\Roaming\A\B\C"

What I have tried:

I use the below script to do this, however, I am not seeing where the local folder is being overwritten by the folder on the server.

Script:

xcopy /s /z /y /r /h /g /e "\\xx.xx.xx.xx\A\B\C\" "C:\Users\%username%\AppData\Roaming\A\B\C"
Posted
Updated 13-Sep-21 21:39pm
Comments
Richard MacCutchan 5-Jul-21 14:49pm    
"I am not seeing where the local folder is being overwritten by the folder on the server."
What are you seeing?
Shemar Forsythe 5-Jul-21 14:53pm    
I do not see any changes.
Richard MacCutchan 5-Jul-21 14:57pm    
What output do you see when the script is running? We have no idea what is going on when you run this so you need to give us full and exact details.
Shemar Forsythe 5-Jul-21 15:16pm    
I have the batch file of this command line, placed in the users' start menu. So when a user logs into a machine. They are able to click on the batch file and have the folder copied to the specified location. So I am not getting any exit codes or such. However, when testing I am seeing where the folder's modified date remains the same. Additionally the folder contains configuration files for an app, when the app is launched after running the script it still remains unconfigured.
Dave Kreskowiak 5-Jul-21 19:23pm    
You're not going to see the date on the folder change if the folders already exist.

The command will merge the content of the server to the users folder. It's not a mirror of what's on the server. If there's a file on the server, that file will overwrite the user copy. If the file does not exist on the server, but does on the user machine, the file will NOT be removed.

You have to log the output of the commands to a file so you can see what's happening.

1 solution

As mentioned in the comments, rather than using C:\Users\%username%\AppData\Roaming, use %APPDATA%. If the user's profile has been redirected, or the system drive is not drive C:, then your script will currently be copying to the wrong path.

You might want to try robocopy instead of xcopy:
robocopy | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900