Script to empty a folder on a daily basis
PostPosted:Mon Jul 20, 2020 2:43 pm
Hello,
I don't know if configuration is the proper place for this topic so mods feel free to move it if not.
Just wondering if someone could help me with a bsh script (or another way) to automatically delete all documents in a specific folder every day at a certain time? I'm using this because I have a scans folder that takes documents in from a scanner and then the user is supposed to then move those documents to the final location that they belong in. I want to delete all remaining files out of this scans folder every day so that users don't get the idea that the scan folder is just another convenient storage location.
I don't know if this has to be a bsh script or if something can be done with automation. I've tried a few calls to the API but I don't know what call to use to delete them.
Here is what I have - some of the code is commented as I was testing but this is the general idea:
Rich
I don't know if configuration is the proper place for this topic so mods feel free to move it if not.
Just wondering if someone could help me with a bsh script (or another way) to automatically delete all documents in a specific folder every day at a certain time? I'm using this because I have a scans folder that takes documents in from a scanner and then the user is supposed to then move those documents to the final location that they belong in. I want to delete all remaining files out of this scans folder every day so that users don't get the idea that the scan folder is just another convenient storage location.
I don't know if this has to be a bsh script or if something can be done with automation. I've tried a few calls to the API but I don't know what call to use to delete them.
Here is what I have - some of the code is commented as I was testing but this is the general idea:
Code: Select all
Any help would be greatly appreciated! import com.openkm.api.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.db.stuff.*;
String token = DbSessionManager.getInstance().getSystemToken();
OKMFolder trash : OKMFolder.getInstance().getChildren(token, "/okm:root/FromScanner/"));
print ("Scanner path: " + trash.getPath() + "<br/>");
/*for (Folder trash : OKMFolder.getInstance().getChildren(token, "/okm:root/FromScanner/")) {
print("Trash: " + trash.getPath()+"<br/>");
for (Folder fld : OKMFolder.getInstance().getChildren(token, trash.getPath())) {
print("About to delete folder: " + fld.getPath() + "<br/>");
//OKMFolder.getInstance().purge(token, fld.getPath());
}
for (Document doc : OKMDocument.getInstance().getChildren(token, trash.getPath())) {
print("About to delete document: " + doc.getPath() + "<br/>");
if (OKMDocument.getInstance().isLocked(token, doc.getPath())) {
print("Unlocking Document: " + doc.getPath() + "<br/>");
OKMDocument.getInstance().forceUnlock(token, doc.getPath());
}
print("Purged Document " + doc.getPath() + "<br/>");
//OKMDocument.getInstance().purge(token, doc.getPath());
}
/*for (Mail mail : OKMMail.getInstance().getChildren(token, trash.getPath())) {
print("About to delete mail: " + mail.getPath() + "<br/>");
OKMMail.getInstance().purge(token, mail.getPath());
}*/
}
print ("End of Script! <br />");
Rich