@RunWith(SpringRunner.class)
@Slf4j
public class CopyFile {
@Test
public void getNewFile() {
String path = "E:\\work\\src";
String dstPath = "E:\\work\\dst";
String date = "2020-12-15";
List<String> exclude = new ArrayList<String>() {{
add(".svn");
add("logs");
}};
ls(path, date, exclude,path,dstPath);
}
private void ls(String path, String date, List<String> exclude,String rootSrc,String rootDst) {
Date afterDate = DateUtil.parse(date);
File[] ls = FileUtil.ls(path);
for (File f :
ls) {
if ( afterDate.before(DateUtil.date(f.lastModified()))
&& f.isFile()) {
String dstPath = StrUtil.replace(f.getPath(), rootSrc, rootDst);
FileUtil.copy(f.getPath(),dstPath,true);
// log.info("{},{},{}", f, DateUtil.date(f.lastModified()),dstPath);
}
if (f.isDirectory() && exclude.stream().filter(s -> f.getName().equals(s)).count() == 0) {
ls(f.getPath(), date, exclude,rootSrc,rootDst);
}
}
}
}