Hello,
I made this button so I wanted to share it with you in case it is useful for you as it is for me
The needed :
- I wanted to delete SECURELY some folder and files which are empty (empty folder or folders containing empty files, and empty files).
So I wrote this button in order to warm me if some files or directories are not empty (in that case I know that the files or directories are not really empty are I supposed).
The button
@nodeselect
@script jscript
function CheckIfDirectoryNotContainFiles(path) {
flag = false;
DOpus.Output("Working on path : \"" + path + "\"");
var folderEnum = DOpus.FSUtil.ReadDir(path, true);
while (!folderEnum.complete)
{
childElementPath = folderEnum.next();
type = DOpus.FSUtil.GetType(childElementPath);
DOpus.Output("Discovered Child Element path : \"" + childElementPath + "\" of type \"" + type + "\".");
if (type == "dir") {
result = CheckIfDirectoryNotContainFiles(childElementPath);
if (result == true)
{
DOpus.Output("Setting flag to true because there is a directory \"" + childElementPath + "\" inside this directory \"" + path + "\" which contain a not empty file.");
flag = true;
break;
}
}
else
{
result = CheckIfFileIsEmpty(childElementPath);
if (result == true)
{
DOpus.Output("Setting flag to true because there is a file \"" + childElementPath + "\" inside this directory \"" + path + "\" which is not empty file.");
flag = true;
break
}
}
}
return flag;
}
function CheckIfFileIsEmpty(path) {
flag = false;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.GetFile(path);
fileSize = file.size;
DOpus.Output("Discover file : \"" + path + "\" with size \"" + fileSize + "\".");
if (file.size > 0)
{
DOpus.Output("Setting flag to true cause the file is not empty.");
flag = true;
}
else
{
DOpus.Output("Setting flag to false cause the file is empty.");
}
return flag;
}
function OnClick(ClickData) {
var cmd = ClickData.func.command;
cmd.deselect = false;
var tab = ClickData.func.sourcetab;
var count = tab.selstats.selfiles;
var notEmptyFiles = [];
var notEmptyDirs = [];
//DOpus.Output (count);
var enumFiles = new Enumerator(tab.selected);
for (enumFiles; !enumFiles.atEnd(); enumFiles.moveNext())
{
path = enumFiles.item()
type = DOpus.FSUtil.GetType(path);
DOpus.Output("Type : " + type);
if (type == "dir") {
flag = CheckIfDirectoryNotContainFiles(path);
if (flag)
{
notEmptyDirs.push(DOpus.FSUtil.NewPath(path).filepart);
}
}
else
{
flag = CheckIfFileIsEmpty(path);
if (flag)
{
notEmptyFiles.push(DOpus.FSUtil.NewPath(path).filepart);
}
}
}
if (notEmptyDirs.length > 0 || notEmptyFiles.length > 0)
{
DOpus.Output("No Empty");
var msg = ""
msg += "At least"
if (notEmptyDirs.length > 0) {
msg += " one directory"
}
if (notEmptyFiles.length > 0) {
if (notEmptyDirs.length > 0) {
msg += " and"
}
msg += " one file"
}
msg += " not empty !"
msg += "\n"
msg += "\n"
if (notEmptyDirs.length > 0) {
msg += "Directories : " + '\n'
}
for (var i = 0; i < notEmptyDirs.length; i++)
{
msg += "- " + notEmptyDirs[i] + '\n'
}
if (notEmptyFiles.length > 0) {
msg += "Files : " + '\n'
}
for (var i = 0; i < notEmptyFiles.length; i++)
{
msg += "- " + notEmptyFiles[i] + '\n'
}
DOpus.Dlg.Request(msg, "Cancel", "Cancel", dlg);
}
else
{
DOpus.Output("Empty");
var dlg = DOpus.Dlg
var msg = ""
msg += "All directories/files are empty !"
msg += "\n"
msg += "Confirm deletion ?"
var result = DOpus.Dlg.Request(msg, "Confirm|Cancel", "Confirm", dlg);
DOpus.Output (result);
if (result == 1)
{
cmd.RunCommand("Delete QUIET");
}
}
}