I want to copy files across computers on the network using a bat file (I want to run the bat file in windows scheduler) but only have files copied based on their last modified dates, e.g. only copy files across to another computer only if the last modified date is older than 3 months then when the coping is done have the copied files delete on the source computer.
Robocopy (included in Windows 7+, downloadable for older versions from Microsoft's site) has options that do exactly what you need.
Robocopy /mov /minage:90 [src] [dest]
would seem to be close to what you need.
Related
I have set up remote sync in my eclipse to copy jsp and js files at different locations. I am observing that sometimes because of this sync (I need to keep build auto option enabled) eclipse is hanging and I need to kill the process.In windows do we have any option to sync two local folders. I searched but options I am getting through third party software. I am using my office laptop, so don't want to use any third party software and want to check if windows provide any easy option for that.
I miss unix and rsync :(
Currently I am using a bat file to copy these files. I think robocopy is a good option too.
xcopy /s /d /y source folder destination foler
Fortunately, there is a useful little program in Windows called robocopy that ships with Win7 and above.
https://technet.microsoft.com/en-us/library/cc733145.aspx
robocopy <source> <destination> /mir /copyall
This is what you can use to copy a source directory to a target directory including all subdirectories, files, and metadata. It's uni-directional so won't check both ways, but there are time and change based triggers you can set with a windows startup task so you can make the folders auto-sync as you work.
If you read the link, you'll find the /mot: and /mon: flags which will watch the folders for changes/wait a certain amount of time then copy again.
In addition, it is really good at logging output, and is excellent when used as a system startup process.
I try to sync files from my Windows 7 computer to my Freebox (running Linux
I used rsync from unix like terminal (MobaXterm) and xcopy directly from windows bash as well.
In both case, whatever the set of option I used (inclusing operations on file attributes), I am unable to sync properly.
Problem is that each file is considered as new at each sync, and hence copied again, even if unmodified.
Problem comes from the file system. Windows is usually NTFS while Freebox (and some Linux) is FAT32 (in general not NTFS). File comparison based on dates concludes on differences between files. Using robocopy command on window with special option /fft solves the issue.
Example:
robocopy src dest /fft /e /purge
Will copy all files recursively from src to dest, removing on dest the non existing ones on src and handling correctly the files date attributes through different file systems, avoiding unecessary recopy.
I would like to be able to copy all files from various folders and combine them into a single folder using a Windows batch file. That is fairly easy to do for me. But if the file already exists on the destination, I would like it to only override the file if it's newer.
copy c:\pics\ to d:\
Thanks.
You can use xcopy for more options if the source dirs are 2-3-5 (write separate xcopy lines for each). If the dirs are too many, you can use archiver like WinRar (or its command line rar.exe) with #list option where are stored the source dirs. In the batch file call RAR 2 times - first to pack all source files to one archive, then to unrar them in single folder (with E option, not X). Finally, you delete the .rar file. See the extra options to skip older files, omit prompts, etc.
I am looking for a batch code that will transfer all files inside folders. Then it will transfer them into the location.
D:\Transfered Files\
And it will keep the exact folder/file names.
For example I want everything transfered from
C:\Users\
C:\Program Files\
I have tried this and it works:
xcopy source destination /Y
Just save this in a batch file of course change the directories as you see fit.
Also note that the '/Y' parameter says that if files exist in the destination overwrite them. If you remove it, it will ask you about each file separately.
If you think this isn't good enough you can use robocopy:
robocopy source destination
Again you need to change the source and the destination directories and put the line in batch file.
I have used both and both works 100%. I have a windows 7 home premium 64x.
I'm building an application that has quite a few files that need to be included in the destination directory. So far, there haven't been very many files so I would simply change the settings of each file individually to Copy to Output Directory :: Copy if newer. The problem now is that I'm adding files at an exponential rate.
Do any of you know how to make all of the files that are sub of the "Some_Directory" have the Copy to Output Directory :: Copy if newer set how I want it?
You cam use a post-build event.
Using following posts, I made a post event that does exactly what you want:
Copying files into the application folder at compile time
Copy to Output Directory copies folder structure but only want to copy files
Visual Studio adds .dll and .pdb to project after compiling
Now, you can easily edit Post-build events, go to your project settings and go to the Compile tab, now click the Build Events and put following line in the *Post-build event command line" text box:
xcopy "$(ProjectDir)Test\*.*" "$(TargetDir)Test\\" /E /I /F /Y
See this image:
In your case you will have to change "Test" by "some_directory" and that's all.
There is one caveat, however. This copies every file every time my project builds. The folder that is being copied is over 3MB (I'm developing quite a large project). This makes debugging take quite a long time because every time I do a build it has to move all of the content over. Is there a way to make it only copy over files that have been updated since the last build? This is why I was using the Copy if newer option.
You can add the /D parameter (you can look that up with xcopy /? in your command prompt).
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
You can write your own custom Post-Build event (Select project -> Properties -> Build Events) with xcopy command. You can use $(solution) macro for your solution directory and specify relative path to your files.
I had the same issue, but the accepted answer didn't solve it. What worked for me was to enable deployment in Local.testsettings (under Solution Items).