I'm having trouble labeling folders gray when they are blank. I have used the thread linked below for guidance, in which I modified the script to ignore files that mess with the folder size, in this case "desktop.ini".
I'm running into one small issue where the main sub folder will not show up gray if there are multiple subfolders that are also technically empty that contain desktop.ini only because I would assume the script only looks through the main folder and not the subfolders. I can add a field to also look for the size, but if I have text files or other small documents it could be inaccurate. How can I make sure that they all show up gray.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "EmptyDirExceptPart";
initData.version = "1.0";
initData.copyright = "(c) 2017 jpotter";
// initData.url = "https://resource.dopus.com/viewforum.php?f=35";
initData.desc = "";
initData.default_enable = true;
initData.min_version = "12.0";
var col = initData.AddColumn();
col.name = "EmptyDirExceptPart";
col.method = "OnEmptyDirExceptPart";
col.label = "EmptyDirExceptPart";
col.justify = "left";
col.autogroup = true;
}
// Implement the EmptyDirExceptPart column
function OnEmptyDirExceptPart(scriptColData)
{
if (!scriptColData.item.is_dir) return;
var readDir = DOpus.FSUtil.ReadDir(scriptColData.item);
while (!readDir.complete) {
var item = readDir.Next()
if (/*item.is_dir || */item.name != "desktop.ini")
{
scriptColData.value = "0";
return;
}
}
readDir.Close();
scriptColData.value = "1";
}
I would also move the Script Column clause to the bottom of the list, so it is checked last, as launching a script will take longer than the other two clauses and there's no point launching the script for things that aren't folders.
So it doesn't appear to be working. It looks like if there are any subfolders within the folder, that folder doesn't work. How would you ignore the subfolders if the subfolders are empty. If it contains desktop.ini it should be considered empty.
Refer to the image below, folders "test" and "test2" should also be gray.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "EmptyDirExceptPart";
initData.version = "1.0";
initData.copyright = "(c) 2017 jpotter";
// initData.url = "https://resource.dopus.com/viewforum.php?f=35";
initData.desc = "";
initData.default_enable = true;
initData.min_version = "12.0";
var col = initData.AddColumn();
col.name = "EmptyDirExceptPart";
col.method = "OnEmptyDirExceptPart";
col.label = "EmptyDirExceptPart";
col.justify = "left";
col.autogroup = true;
}
// Implement the EmptyDirExceptPart column
function OnEmptyDirExceptPart(scriptColData)
{
if (!scriptColData.item.is_dir) return;
var readDir = DOpus.FSUtil.ReadDir(scriptColData.item, 'r');
while (!readDir.complete) {
var item = readDir.Next()
if (item.is_dir || item.name != "desktop.ini")
{
scriptColData.value = "0";
return;
}
}
readDir.Close();
scriptColData.value = "1";
}
Almost. When there is a subfolder within a folder and it contains desktop.ini, it still doesn't work. It does work if the subfolder doesn't have desktop.ini
There are folders like System Volume Information in the root of most drives that can't be accessed. It might be trying to look inside one of those.
You really don't want a label like that to be applied everywhere though. It will create a lot of unnecessary SSD/HDD access every time you change folders, which is bad for performance.
Restrict it to the folders you need it in, and where there is only a shallow set of sub-folders to test, and put the path restriction as the first clause in the filter (before the Script Column, so it doesn't run the script in places it doesn't need to).
Alternatively, remove it from the global labels list and add it to the Labels tab of a Folder Format which matches the paths you need it in.
The "Empty folders everywhere" will also slow things down a little, although a lot less. Up to you, but I'd generally recommend avoiding that kind of filter outside of places where you really need it.
You can push Ctrl-K (Edit > Calculate Folder Sizes) to quickly calculate folder sizes and find empty folders when needed in random folders. Although empty folders don't cause problems so they aren't something to worry too much about.