Xcopy and replacing a file - cmd

When I'm using Xcopy command in CMD to copy and replace a file from the user's download location to another location, I'm getting invalid number of parameters.
Here's my code:
xcopy /y C:\%userprofile%\downloads\XXXXt\XXXX C:\Program Files (x86)\XXX\XXX\common\XXXX\XXXX\Managed\XXXX
The XXX's represent game files for which we are replacing to mod the game.

%USERPROFILE% includes the drive letter. Replace C:\%USERPROFILE% with just %USERPROFILE%.
There are space in Program Files (x86), so you need to place the destination in double quotes.
Overall, the command should then be xcopy /y "%userprofile%\Downloads\XXXX\XXXX" "C:\Program Files (x86)\XXX\XXX\common\XXXX\XXXX\Managed\XXXX".

Related

Batch program to copy file when there is a change in source folder

I need a batch program that will copy files from source folder to destination folder whenever there is a change(new files added or files modified) in source folder and restart a specific service.
Refer to the help of xcopy /? using the switch /D
/D : Copy files changed on or after the specified date.
If no date is given, copy only files whose
source date/time is newer than the destination time.
Syntax :
XCOPY source [destination] [options]
Remark :
So, in this batch file below, if you have any spaces in your directory names, you need to enclose them in double quotes.
#echo off
Set SourceDir="C\My Source\stuff"
Set TargetDir="D:\My Backup\stuff"
xcopy %SourceDir% %TargetDir% /i /d /y /e
/D : copy only files whose source date/time is newer than the destination time.
/E : To copy everything, including new directories, you should add the /e switch
/Y : Suppress prompt to confirm overwriting a file.
/I : If in doubt always assume the destination is a folder e.g. when the destination does not exist.

$(SolutionDir) in MS VisualStudio Build events

XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" ".\"
is the command right now. Which tell that the directory to copy files is at same level where the sln is.
My Question is: I want to copy the files to a directory which is one level above the solution directory. How the command should be?
If you are trying to change the destination dir, and make it one level up, try putting two dots instead of one:
XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" "..\"

Windows xcopy 0 File(s) copied

I am trying to copy a directory but get the following:
xcopy ..\node_modules\ \node_modules\
0 File(s) copied
I run as administrator, but still get the error. Any ideas please?
p.s I actually use the following to stipulate it's a directory. But the above also fails:
echo d | xcopy /d /y ..\node_modules\ \node_modules\
Thanks
You can use the xcopy /E flag to copy the entire directory and subdirectories. Also remove the starting \ of the destination. The trailing slash should prevent the file or directory prompt.
xcopy /E ..\node_modules node_modules\
xcopy ..\node_modules\* \node_modules\
You are specifying the source directory, but not which files to copy.
To copy all the contents like folder, sub-folder or chain of folders we can use below command:
xcopy file-to-copy-path\ where-to-copy-path\ /s /i
/s copies folders and sub-folders
/i If in doubt always assume the destination is a folder e.g. when the destination does not exist.

Batch Script command at prompt

This may seem like a stupid question but I have this Simple Script:
#ECHO OFF
XCOPY c:\test c:\backupfolder /m /e
Because there is no folder backupfolder it prompts you if it is a folder or file how using the script to automatically put in The Letter "D" for directory in the prompt
Thanks
When copying to a folder, which is the usual case, add a backslash to the end of the path.
Adding quotes protects the command from spaces etc in the paths.
#ECHO OFF
XCOPY "c:\test\*.*" "c:\backupfolder\" /m /e
The /i switch causes xcopy to assume the destination is a directory as long as there is more than one file to copy.
But to make it work even if copying just one file, you could simply create the directory first:
#echo off
mkdir c:\backupfolder 2>NULL
xcopy /me c:\test c:\backupfolder
The 2>NULL (redirecting standard error to NULL) suppresses the error message that occurs if the directory already exists.

Windows cmd shell xcopy to network directory doesn't work

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f

Resources