Reputation: 29573
I currently need to send files from a folder, i want the service i am running to check in the folder every half an hour....how am i able to know if the folder is clear?
Upvotes: 12
Views: 22070
Reputation: 442
if you have the path, you can make a File object check for entries (using file.isDirectory() and file.list())
Upvotes: 2
Reputation: 33509
if (file.isDirectory()) {
String[] files = file.list();
if (files.length == 0) {
//directory is empty
}
}
Upvotes: 7
Reputation: 27326
File directory = new File("/path/to/folder");
File[] contents = directory.listFiles();
// the directory file is not really a directory..
if (contents == null) {
}
// Folder is empty
else if (contents.length == 0) {
}
// Folder contains files
else {
}
Upvotes: 35