I was moving a zip file from source directory to target directory but since the target directory may also contain some other files like text files , image , documents files , zip files also.
I have to look and track the zip files whose name is starting with pattern abcd and after that it could be anything like abcd4567fg.zip so I have to catch such zip files and also have to look their creation time since my ultimate goal is not to keep such zip files whose name is starting with abcd in the target directory if they are created before seven days , I have come up with the below solution but it is not appropriate please advise
long timeInEpoch = System.currentTimeMillis(); // slightly faster than new Date().getTimeInMillis();
File f = new File("/tmp");
if (f.isDirectory()) {
final File[] files = f.listFiles();
for(int i =0; i < files.length ; i++ ) {
if( timeInEpoch - f.lastModifiedDate() > 1000*60*60*24*7 )
files[i].delete();
}
System.out.println(fileList);
}