Copy the most recent files from sourcefolder and check their existence in destinationfolder before copying
2 views (last 30 days)
Show older comments
The thing is:I'm trying to develop a script to regularly copy files from a sourcefolder to a destinationfolder. Nevertheless, I want to make sure it copies only the most recent and modified data (given the fact the older files don't get their names changed), in order to get a more efficient and quicker programme. Could you help me out, please?? Tks a lot!
0 Comments
Answers (2)
Adam
on 4 Mar 2016
Edited: Adam
on 4 Mar 2016
You can use something like
sourceFile = 'D:\SomeLocation\somefile.m;
destinationFile = 'D:\SomeOtherLocation\somefile.m;
import java.io.File
source = File( sourceFile );
destination = File( destinationFile );
if source.lastModified >destination.lastModified
copyfile( sourceFile, destinationFile );
end
Note that I wrote that based on example code I have used with a few changes so it might not be 100% syntactically correct, but I did a quick test of some of the functionality before posting it.
If a file does not exist then the 'lastModified' field of java.io.File returns 0 so you can do the lastModified > test without needing to check that as the source file will always be > 0.
0 Comments
Walter Roberson
on 4 Mar 2016
sourceFile = 'D:\SomeLocation\somefile.m;
destinationFile = 'D:\SomeOtherLocation\somefile.m;
source_info = dir(sourceFile);
dest_info = dir(destinationFile);
if ~isempty(source_dir) && (isempty(dest_info) || dest_info.datenum < source_info.datenum)
copyfile( sourceFile, destinationFile );
end
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!