Copy Directory - Post Build Event - c++

How do I copy some directory from one place to another (not file by file)
in post build event (whats the comman line??). im using vs 2005 (c++ project)

For more clarification, here is an example that copies a folder called "ApplicationFiles" from the root of your project to the destination (binary) folder:
xcopy "$(ProjectDir)ApplicationFiles" "$(TargetDir)ApplicationFiles" /e /y /i /r

Thanks, just what I needed. Options documented here for future reference:
/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/I If destination does not exist and copying more than one file, assumes that destination must be a directory.
/R Overwrites read-only files.

The commandline is simply a batch script that is executed upon completion of the build. Therefore, you can just use regular Windows shell commands, such as mkdir, copy, ... To copy whole directories recursively, use xcopy <src> <dest> /E.

Related

Postbuild Event Copy build output to parent sibling undertermined folder

I have two solutions, WildCougarFarm and WildLionFarm both depending on a shared library
\Folder 1
\WildCougarFarm
\WildSharedLib (Separate Solution)
\Folder 2
\WildLionFarm
\WildSharedLib (Separate Solution)
When \WildSharedLib is built I want to run a post build script that automatically copies the output directories contents to the sibling \Wild[Lion|Cougar]Farm solution folder. Depending on whether WildLionFarm exists, I want it to copy with say wildHorseFarm in future.
I need an xcopy expression with a regex but xcopy doesn't support this.
Any ideas how I can accomplish this?
I figured it out.
This is pretty cool, because it uses a foreach type loop... so we ask if the parent folder of the solution contains any folders that end in farm. For any returned it will execute the xcopy statement to copy the files to that folder.
for /d %%a in ($(SolutionDir)..\*farm) do xcopy $(TargetDir)*.* "%%a\dependancies" /s /e /f /h /k /y /i

Copy list of file names from multiple directories

i'm new to the forum. I need some advice. I need help with a code to take a text file with a list of file names and copy the files from multiple folders in to one folder, but it has to end up with the most recent modified date of the file. There are hundreds of folders containing the thousands of files.
I have a batch code below to copy the files, but it does not always end up with the newest file. If there is some way to make the code below search the folders in numerical order, that would work instead of it searching in a random order. I do not care if the code i end up using is batch, vbs, or whatever.
mkdir %userprofile%\desktop\print
set FIILELIST=%userprofile%\desktop\print.txt
set FILESPATH="\\server\folder"
set DESTPATH=%userprofile%\desktop\print
for /f %%X in (%FIILELIST%) do call :COPY_FILES "%%X"
goto :eof
:COPY_FILES
for /r %FILESPATH% %%I in (%~1) do copy "%%I" "%DESTPATH%"
for /r %FILESPATH% %%I in (%~1) do Xcopy /D "%%I" "%DESTPATH%"
XCOPY /D will only copy if the destination file does not exist or if the destination file is older than the source.

Batch: Create a list of folders and then copy multiple files/folders into all of them

I am a CAD manager in need of some help. I am no programmer, but I have a very basic understanding of DOS commands so I thought I could use XCOPY to do this, but I don't know how.
I have a folder, under which are hundreds of subfolders that change with time (each employee has one folder) so maintaining a manual listing (as I have been doing) is not easy.
I also have a _TEMPLATE subfolder that contains several files and folders.
I would like to copy the contents of the _TEMPLATE folder into all the other subfolders, overwriting all existing files and creating all non-existing folders.
From what I've seen with some searching in here it seems to pretty easy to accomplish these two tasks (to create the list of folders and to copy into a list of folders) but I'm just too dumb to understand how to combine the two into one file :)
EDIT :
Well, I've found a PowerShell script that does what I need perfectly. Since I managed to run the PowerShell I guess my problem is solved :D
$folder = Get-Childitem -name -exclude *.*,_TEMPLATE
foreach ($f in $folder)
{xcopy "_TEMPLATE\*.*" "$f" /e /r /y }
Thanks for all the fish ;)
Try this:
#echo off &setlocal
cd /d "RootFolder=X:\folder\to\my data"
for /d %%a in (*) do xcopy "_TEMPLATE" "%%~fa" /sihrky
For xcopy options see xcopy /?, to test the command without writing add option /l.

Windows XP Batch IF & XCOPY

I've been struggling with trying to get the below (example) batch file to work on Windows XP SP3. The IF NOT EXIST part seems to work, but I keep receiving the "Does <path\filename.ext> specify a file name or directory name on the target" message despite using the /I flag on XCOPY:
#IF NOT EXIST "\\SERVER\PATH\TO\FILE DIR" (
MKDIR "\\SERVER\PATH\TO\FILE DIR"
XCOPY "\\SERVER\PATH\TO\ORIG FILE\FILE TEMP.XLSM" "\\SERVER\PATH\TO\FILE DIR\FILE FINAL.XLSM" /I
) ELSE (
XCOPY "\\SERVER\PATH\TO\ORIG FILE\FILE TEMP.XLSM" "\\SERVER\PATH\TO\FILE DIR\FILE FINAL.XLSM" /I
)
My understanding is that with the /I switch, XCOPY should create the directory structure if it doesn't exist - at least it does when I don't specify a file name. Unfortunately for the requirements of this project, I must specify a file name and cannot keep the original as it's a template file that gets manipulated with an automated process every day.
So, I tried to get around the issue with XCOPY and the directory path not existing by checking for the existence of the path, and if it's not there, creating it with the MKDIR command and then copying the file - but XCOPY still prompts as to whether the destination is a file or directory, which doesn't make sense but maybe I'm missing something.
Just to be clear, this is on Windows XP SP3.
Any ideas?
You might find it easier to do something like this:
md "\\SERVER\PATH\TO\FILE DIR" 2>NUL
copy "\\SERVER\PATH\TO\ORIG FILE\FILE TEMP.XLSM" "\\SERVER\PATH\TO\FILE DIR\FILE FINAL.XLSM"
The initial 'md' will attempt to create the directory. If it already exists, it will output an error message to STDERR. The 2>NUL redirects that to Windows' built-in "null device", which is to say, it just swallows the error message. Assuming you have the appropriate permissions, you can be sure that this directory exists now.
The copy command just copies your file. No need to use xcopy to copy a single file - that's both overkill and fraught with little gotchas like being prompted whether it's a file or directory.
Since the destination file doesn't exist before you copy, xcopy isn't sure if it needs to create a new directory called "FILE FINAL.XLSM", and put the file in there. By the way, since you already create the destination dir, you don't need the /I on your xcopy. Here are a couple ways to do what you want:
echo F | xcopy .... (feed the "F" answer to xcopy)
copy .... (you don't need to use xcopy for a single file)
echo f|XCOPY "\\SERVER\PATH\TO\ORIG FILE\FILE TEMP.XLSM" "\\SERVER\PATH\TO\FILE DIR\FILE FINAL.XLSM"
should copy the file AND create the directory. No idea why the option to specify "this is a file" wasn't made available, but RTFM - the /i switch is only effective if you are copying MORE than one file, and specifying \ as the last character of the destination name tells XCOPY that the target is a directoryname in any case, so /i sems redundant.
However, be careful if you follow the copy route. It's better in general to use copy /b because plain copy may fail to properly copy some filetypes (like .MPGs) - it may stop on the first ^Z. copy /b appears safe however.

Post-Build script throws error in VIsual Studio 2010

I've seen several threads with the same issue, but none of the solutions seems to work for me so I'm trying it here.
I need a post-build script in VS2010 that moves a .lib file to a directroy (which possibly dosn't exist yet; if so create it).
I am using this, which returns error code 2:
xcopy /y "$(TargetDir)$(ProjectName).lib" "$(SolutionDir)lib\$(ProjectName).lib"
Also tried, which returns error code 1: (what is the difference?)
copy /y "$(TargetDir)$(ProjectName).lib" "$(SolutionDir)lib\$(ProjectName).lib"
The most common issues people seem to hav is the lack of quotes on paths, but I have that.
Why dosn't it work?
This ought to be closer:
if not exist "$(SolutionDir)lib" md "$(SolutionDir)lib"
xcopy /y /d "$(TargetPath)" "$(SolutionDir)lib"
After a quick test on the command line what's happening with copy is it is failing because the directory does not exist. What is happening with xcopy is it is failing when it prompts for whether the target is a file or directory when it finds the directory doesn't exist. /-Y may be set in your COPYCMD environment variable or your target path may be misleading causing a prompt for whether the target is a directory or file which is not supressed by the /Y flag for overwrite.
Example: xcopy /Y "C:\test.txt" "missingdirectory\test5.txt"
Obviously the easiest solution is to check if the directory exists and create it if it's missing before doing the copy in your post-build script.