Nant - copy only modifiled files - nant

I'm looking for Nant script syntax that will copy from one folder to an other all files that were modified within last 5 days.
How I can cause to to include only modified files?
Thanks

You could use robocopy. Robocopy has an option to exclude older files. See this link.
http://en.wikipedia.org/wiki/Robocopy
You would then run Robocopy for a nAnt exec task.
Hope this helps
Shiraz

The idea is quite simple:
When you need to copy files from folder 1 to folder 2 which are modified relative to each other:
<exec program="C:\Windows\System32\xcopy.exe" failonerror="false" >
<arg line="${source} ${destination} /D /E /C /Q /H /R /Y /K" />
</exec>
However, if you need to check timestamp too, you would have to create some kind of filter. This you could do either in a batch file or writing your own console app.

Related

Simple xcopy script using variables and a target text list to copy a folder to different computers

I wrote a script that wil copy a particular folder to a list of hosts, stored in a text file.
It works great from a short source path but fails to find the folder when located in a long path, which is how i need it to function.
Thsi what i tried, which should copy the folder to the list in the text.
Code below
set source=%~dp0%data
set source2=%~dp0%\target.txt
FOR /F "TOKENS=*" %%A IN (%source2%) DO XCOPY /d /y /f /i "%source%" "\%%~A\c$\users\test\test"
pause
Error: The system cannot find the file C:\Users\lenovo\OneDrive\Company\Red.
The above path is not the full path.
I understand there may well be more modern ways to achive this such as ropcopy or powershell and am open to ideas if this is not teh best method.
Thanks in advance for any help

XCOPY not overwriting files

Hello I use the following code inside a BAT file to move files but the xcopy fails to overwrite the files:
xcopy "C:\Users\AGL\Desktop\DATA\MT4BACK" "C:\Users\AGL\AppData\Roaming\MetaQuotes\Terminal\2010C2441A263399B34F537D91A53AC9" /e /y /r
Please let me know what migth be the problem
For more info run xcopy help in CMD, this will explain you all possibilities.
You can try to use different options then.
EDIT
You can add PAUSE at the end of bat file, so you can read xcopy output info

Having XCopy copy a file and not overwrite the previous one if it exists (without prompting)

I'm sending commands to a remote computer in order to have it copy a file.
I want the file to be copied, but not to overwrite the previous file with the same name (if it exists).
I also need the command to run without any prompts (xcopy likes to prompt whether the target name I've specified is file or directory, and it will also prompt about overwriting a file).
I have good results with xcopy /d.
It will copy NEWER files, and since we can assume that existing files have same time-stamp, you will copy only files that don't exist.
just in case anyone else finds this:
robocopy x:\sourcefolder Y:\destfolder /s /e /r:0 /z
much better than xcopy, even gives you a table at the end informing of any failed or skipped files. Doesn't prompt to not overwrite.
Well, there's a certain remedy! It has helped me with saving much of my effort and time on Win10 while writing a setup for our product demo.
Just try to use piping:
#ECHO N|COPY /-Y SourceFiles Destination
As an example I used this piece of code so that I would have a clean gentle quiet and safe copy!
#FOR /D %%F in ("FooPath") DO #(
#ECHO N|COPY /-Y ^"%%~npdxF\*.*^" ^"GooPath^" 3>NUL 2>NUL >NUL
)
where obviously FooPath is the source and GooPath is the destination.
Enjoy!
(main source: https://ss64.com/nt/copy.html)
Following command copy files and folder but not override file if already exist.
xcopy "*.*" "C:\test\" /s /y /d
No way to make it NOT overwrite as far as I know. but /Y will make it overwrite. and /I will get rid of the file/dict prompt. See xcopy /? for all options
You can also use the replace command. It has two modes: to add files that don't exist there or replace files that do exist. You want the previous mode:
replace <path1> <path2> /A
I had to copy AND rename files, so I got the prompt about creating a file or a directory.
This is the, rather "hackish" way I did it:
ECHO F | XCOPY /D "C:\install\dummy\dummy.pdf" "C:\Archive\fffc810e-f01a-47e8-a000-5903fc56f0ec.pdf"
XCOPY will use the "F" to indicate it should create the target as a file:
C:\install>ECHO F | XCOPY /D "C:\install\dummy\dummy.html" "C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html"
Does C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html specify a file name or directory name on the target
(F = file, D = directory)? F
C:\install\dummy\dummy.html
1 File(s) copied
I've also verified this command leaves existing files alone. (You should too :-)

XCOPY switch to create specified directory if it doesn't exist?

I am using XCOPY in a post-build event to copy compiled DLLs from their output folders to the main app's output folder. The DLLs are being copied to a "Modules" subfolder in the main app output folder, like this:
xcopy "$(TargetPath)" "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\"
The command works fine if the Modules folder exists, but I have discovered during testing that if the folder doesn't exist, XCOPY doesn't create it, and the command fails.
Is there an XCOPY switch that will cause the folder to be created if it doesn't exist? If not, what would I add to my post-build event to create the folder if it doesn't exist? Thanks for your help.
Answer to use "/I" is working but with little trick - in target you must end with character \ to tell xcopy that target is directory and not file!
Example:
xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)_DropFolder" /F /R /Y /I
does not work and return code 2, but this one:
xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)_DropFolder\" /F /R /Y /I
Command line arguments used in my sample:
/F - Displays full source & target file names
/R - This will overwrite read-only files
/Y - Suppresses prompting to overwrite an existing file(s)
/I - Assumes that destination is directory (but must ends with \)
I tried this on the command line using
D:\>xcopy myfile.dat xcopytest\test\
and the target directory was properly created.
If not you can create the target dir using the mkdir command with cmd's command extensions enabled like
cmd /x /c mkdir "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\"
('/x' enables command extensions in case they're not enabled by default on your system, I'm not that familiar with cmd)
use
cmd /?
mkdir /?
xcopy /?
for further information :)
I hate the PostBuild step, it allows for too much stuff to happen outside of the build tool's purview. I believe that its better to let MSBuild manage the copy process, and do the updating. You can edit the .csproj file like this:
<Target Name="AfterBuild" Inputs="$(TargetPath)\**">
<Copy SourceFiles="$(TargetPath)\**" DestinationFiles="$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\**" OverwriteReadOnlyFiles="true"></Copy>
</Target>
Use the /i with xcopy and if the directory doesn't exist it will create the directory
for you.
You could use robocopy:
robocopy "$(TargetPath)" "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules" /E
Simple short answer is this:
xcopy /Y /I "$(SolutionDir)<my-src-path>" "$(SolutionDir)<my-dst-path>\"
Simply type in quotes slash delimiter "/" and add to final destination 2 back-slashes "\\"
It's will be create New folders to copy and copy need file(-s).
xcopy ".\myfile" "....folder1/folder2/destination\\"
I tried this on the command.it is working for me.
if "$(OutDir)"=="bin\Debug\"  goto Visual
:TFSBuild
goto exit
:Visual
xcopy /y "$(TargetPath)$(TargetName).dll" "$(ProjectDir)..\Demo"
xcopy /y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\Demo"
goto exit
:exit
Try /E
To get a full list of options: xcopy /?

Making batch file for copying

Can anyone advise me please im using Windows XP Pro on C drive and need to be able to copy a file from one drive to another. This case original will have to be renamed and old file must be put on another Partiton which is on a Server Example K drive.
Alternately There is another option using Windows 7 on a another computer instead of Windows XP Pro. So any answers appreciated.
A quick look on my old DOS book that I saved just in case that I have to make batch files says COPY is the right command.
Syntax:
COPY DRIVE:FILENAME DRIVE:FILENAME
COPY THISFILE THATFILE
If your permissions are setup to allow copying, you can use "UNC" paths to copy files across servers and drives.
Like Noah said, check out ROBOCOPY or the slightly less featured XCOPY.
Enter copy /? or xcopy /? to find out the available options - if you append >file.txt you'll get them in a text file.
XCOPY Command:
xcopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /D /E /C /R /Y
ROBOCOPY Command:
robocopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /R:5 /W:3 /Z /XX /TEE
Either of these should work for you
Have you looked into robocopy?