Customizing Folder Columns

I have a need to count the number of files that match a filename pattern in a directory and show it as a column in the directory itself.

For simplicity I'll use this example:

The filename is given a suffix of -featured if it will be part of a package that is sold to a customer. (IE: WaterfallPhoto -featured.jpg)

So I may have folders with these patterns inside named:

20160105 - Wedding Smith
20160120 - Wedding Jones

and I would like to have a column showing me how many filenames have the pattern "*-featured.jpg" in them.

20160105 - Wedding Smith 33
20160120 - Wedding Jones 47

Is it possible?

thx for any assistance.

It's possible using a script column.

Custom Column - Newest File is a good starting point, since it's a column that looks inside folders.

Link your account if you need detailed scripting help.

Ok I'm a bit stumped. I'm following along but I dont' know jscript at all so I'm not sure how to get counts.

I linked my account.

Here's what I have so far. The comments show what I'm trying to do. The comments show where I get stumped.

// ---======= VBKUP and ELITE column counts ===============
// Routine provides 2 custom folder columns for directory opus: (asterisks are wildcards)
// Column V = Count of number of files in the immediate directory below it that has *vbkup* in the filename 
// Column E = Count of number of files in the immedia directory below it that has a *elite* in the filename
// Function is not recursive.

function OnInit(initData)
{
	initData.name = "Special Files Count";
	initData.desc = "Counts files with -vbkup or -elite";
	initData.copyright = "(C) 2016 JB";
	initData.version = "1.0";
	initData.default_enable = false;
	initData.min_version = "11.5.2"

	var col = initData.AddColumn();
	col.name = "vbkup";
	col.method = "OnNewestFile";
	col.label = "V";
        col.header = "V";
	col.justify = "right";
	col.autogroup = true;
	col.multicol = false;

	var col = initData.AddColumn();
	col.name = "elite";
	col.method = "OnNewestFileRec";
	col.label = "e";
	col.header = "e";
	col.justify = "right";
	col.autogroup = true;
	col.multicol = false;

}


function OnVbkup(scriptColData)
{
	CountFilesMain(scriptColData, false);
}

function OnElite(scriptColData)
{
	CountFilesMain(scriptColData, false);
}


//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================
//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================
//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================


function CountFiles(scriptColData, IsRecursive)
{
	if (scriptColData.item.is_dir)
	{
		FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, IsRecursive);

		NewestItem = null;

		while (!FolderEnum.complete)
		{
			FolderItem = FolderEnum.next;

			if (!FolderItem.is_dir)
			{
				if (NewestItem == null || NewestItem.modify.Compare(FolderItem.modify) < 0)
				{
					NewestItem = FolderItem;
				}
			}
		}

		if (NewestItem != null)
		{
			var isRec = (IsRecursive ? "Rec" : "");

			scriptColData.columns("NewestFileName" + isRec).value = BestItemName(NewestItem) + "";
			scriptColData.columns("NewestFileDate" + isRec).value = NewestItem.modify;

			DateVar = new Date(NewestItem.modify);
			scriptColData.columns("NewestFile" + isRec).value = NewestItem.modify.Format() + " " + BestItemName(NewestItem);
			scriptColData.columns("NewestFile" + isRec).sort = DateVar.toJSON() + " " + BestItemName(NewestItem);
		}
	}
}




can you give me some assistance?

Can anyon help me with this?

Hello, I'm looking for some assistance in adding 2 counts to folders as custom columns.

Any file with the pattern elite should be counted in a column labeled Elite and any file with the pattern vbkup should be counted in the column vbkup.

I do not want this to be recursive. Only the immediate directory below.

After reading the posts on how to create custom columns I tried to use the examples to get me started but I'm stumped in the actual counting part.

Here's what I have so far. (Note: I've never done this before.)

// ---======= VBKUP and ELITE column counts ===============
// Routine provides 2 custom folder columns for directory opus: (asterisks are wildcards)
// Column V = Count of number of files in the immediate directory below it that has *vbkup* in the filename
// Column E = Count of number of files in the immedia directory below it that has a *elite* in the filename
// Function is not recursive.

function OnInit(initData)
{
   initData.name = "Special Files Count";
   initData.desc = "Counts files with -vbkup or -elite";
   initData.copyright = "(C) 2016 JB";
   initData.version = "1.0";
   initData.default_enable = false;
   initData.min_version = "11.5.2"

   var col = initData.AddColumn();
   col.name = "vbkup";
   col.method = "OnNewestFile";
   col.label = "V";
        col.header = "V";
   col.justify = "right";
   col.autogroup = true;
   col.multicol = false;

   var col = initData.AddColumn();
   col.name = "elite";
   col.method = "OnNewestFileRec";
   col.label = "e";
   col.header = "e";
   col.justify = "right";
   col.autogroup = true;
   col.multicol = false;

}


function OnVbkup(scriptColData)
{
   CountFilesMain(scriptColData, false);
}

function OnElite(scriptColData)
{
   CountFilesMain(scriptColData, false);
}


//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================
//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================
//  ----------=============  PRETTY STUMPED BELOW THIS LINE ===========================


function CountFiles(scriptColData, IsRecursive)
{
   if (scriptColData.item.is_dir)
   {
      FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, IsRecursive);

      NewestItem = null;

      while (!FolderEnum.complete)
      {
         FolderItem = FolderEnum.next;

         if (!FolderItem.is_dir)
         {
            if (NewestItem == null || NewestItem.modify.Compare(FolderItem.modify) < 0)
            {
               NewestItem = FolderItem;
            }
         }
      }

      if (NewestItem != null)
      {
         var isRec = (IsRecursive ? "Rec" : "");

         scriptColData.columns("NewestFileName" + isRec).value = BestItemName(NewestItem) + "";
         scriptColData.columns("NewestFileDate" + isRec).value = NewestItem.modify;

         DateVar = new Date(NewestItem.modify);
         scriptColData.columns("NewestFile" + isRec).value = NewestItem.modify.Format() + " " + BestItemName(NewestItem);
         scriptColData.columns("NewestFile" + isRec).sort = DateVar.toJSON() + " " + BestItemName(NewestItem);
      }
   }
}

Any help would be appreciated.

Try this:

// ---======= VBKUP and ELITE column counts ===============
// Routine provides 2 custom folder columns for directory opus: (asterisks are wildcards)
// Column V = Count of number of files in the immediate directory below it that has *vbkup* in the filename
// Column E = Count of number of files in the immedia directory below it that has a *elite* in the filename
// Function is not recursive.

function OnInit(initData)
{
   initData.name = "Special Files Count";
   initData.desc = "Counts files with -vbkup or -elite";
   initData.copyright = "(C) 2016 JB";
   initData.version = "1.0";
   initData.default_enable = false;
   initData.min_version = "11.5.2"

   var col = initData.AddColumn();
   col.name = "vbkup";
   col.method = "OnGetColumn";
   col.label = "V";
   col.header = "V";
   col.justify = "right";
   col.autogroup = true;
   col.type = "number";

   var col = initData.AddColumn();
   col.name = "elite";
   col.method = "OnGetColumn";
   col.label = "e";
   col.header = "e";
   col.justify = "right";
   col.autogroup = true;
   col.type = "number";
}

function OnGetColumn(scriptColData)
{
	var count = 0
	if (scriptColData.item.is_dir)
	{
		FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, false);
		while (!FolderEnum.complete)
		{
			FolderItem = FolderEnum.next;
			if (!FolderItem.is_dir)
			{
				var name = FolderItem.name + "";
				if (name.indexOf(scriptColData.col) > -1)
					++count;
			}
		}
		scriptColData.value = count;
	}
}

This is working so perfectly!!!! It will help me tremendously.

Thank you Jon!!

I just upgraded to version 12.3 and this stopped working. Can anyone give me advice on what to do?

It was working flawlessly in version 11.

Never mind. It turns out that 12.3 just disabled my scripts. I just had to enable it by clicking the checkbox and hitting apply. Then it started working again. WHEW. This is an important script for me.