post-built event xcopy fails with exit code 4 - visual-studio-2013

my Xcopy fails to execute properly after I compile my project.
xcopy "$(SolutionDir)LuaModules\*.*" "$(TargetDir)Modules\" /S /H /Y /C

You have unneeded slash after /S.

$(SolutionDir) gives the directory where the solution is in, but the project ($ProjectDir) gives the folder of your files. I had to use that instead

Related

$(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.

Copying folders on post build in Visual Studio

Lets say I have a project solution, I want to copy the contents of bin/Release folder after the build into another folder named "Deploy"
Source: D:\Solution\bin\Release
Destination: D:\Destinationfolder\bin\deploy
the macros are as follows
TargetDir : D:\Solution\bin\Release
ProjectDir: D:\Solution
I have tried this
xcopy /? $(TargetDir) $(ProjectDir)\..\Bin\Deploy /R /Y /S
This is not working. Am I doing anything wrong? Is there any other way to do this?
Remove the /? from the xcopy command, and add quotes around paths. The .. will take the $(ProjectDir) path back to D:, so the Destinationfolder should also be added.
So: xcopy "$(TargetDir)" "$(ProjectDir)\..\Destinationfolder\Bin\Deploy" /R /Y /S
I would suggest you to create a Publish Profile. If you want to build the project to a desired folder you can simply right click on the project and click Publish.

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

Xcopy complete operation successfully, but the copy does not occur

i'm having a weird problem about copying with Xcopy.
I'm using Windows Server 2008 R2. There is a Batch file (.CMD) - in fact, 2 Batches - which executes many operations. Among them there are 2 Xcopy.
The first Xcopy completes the copy successfully. Then some operations of batch are executed and...the second Xcopy is executed after some time. It shows a successfully status, like "300 files copied" but...the files are not copied !
THE strange behaviour: i put a pause command into the Batch and, after this second weird Xcopy, i run THE SAME command at the Prompt and..it works !!!
I cannot explain this, so i'm asking for help here. The full command is:
xcopy /s /e /h /r /i /y E: D:
As a matter of curiosity/information, the other Xcopy (which worked!) is:
xcopy /s /e /h /r /i /y E: D:
Or....the same command !!! Each one runs in a separated Batch file - the first Batch "calls" the second one.
E: is CD-ROM, so after the first Xcopy, the first Batch asks for another Disc and calls the second Batch, which (supposed) copies entire CD content to D: (HDD).
I'm sorry if the question is silly and i'm not realizing how simple is to correct the erratic behaviour of Xcopy. Thanks in advance...
Thanks very much Bali C !
But i found the problem: the correct syntax is
xcopy /s /e /h /r /i /y E:\ D:\
You can see that the backslashes made all the difference ! The files were being copied to another directory, in fact, the current working directory. With backslashes the copy is fine.
But i appreciate your suggestion...
To copy the entire contents try using
xcopy /e /h /r /i /y /t E:\*.* D:\
I left out the /s as it contradicts the /e switch, I doubt it will be the source of the problem but it's worth a shot. I used the \t switch to copy the directory structure of the source.
I have also used wildcards *.* to copy the contents, rather than just the drive letter, some things work at cmd prompt but not in batch, but try using this.
Another option would be to use robocopy.

Resources