We had the same issue, Folder.find()
was taking around 40 seconds to scan a single folder and to return just one file.
A way much faster solution is to use Folder.getFiles()
and loop on the resultset to get what you need..
For example, if you need to delete all files that have "DELETED" string in filename:
[SLOW] folder.find()
var files = folder.find("DELETE");
for(var x = 0; x < files.length; x++){
files[x].removeFromFolder(folder)
}
[FAST] folder.getFiles()
var files = folder.getFiles();
for(var x = 0; x < files .length; x++){
var fileName = files[x].getName();
if(fileName.indexOf("DELETE") > - 1){
files[x].removeFromFolder(folder)
}
}
The second version, in our particular case scenario, took only 3 seconds to complete.