I want only files containing a fixed pattern in their name,but my code is copying all the files.
code that i am using right now is :
File source = new File("Any Source file path");
File[] listOfFiles = source.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String filename = listOfFiles[i].getName();
if (filename.endsWith(".x") && filename.contains(aPattern)) {
try {
FileUtils.copyDirectory(source, dest));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Example file names which are valid for pattern matching: 2015.11.30.x or ivnr.stats