Find folders that do not have a specific file?

I would like to find all folders that DO NOT have a specific file. I tried some things, but gave up.

It can be done but would require some scripting.

We can help with some more detail:

  • What's the filename you want to check for?
  • If folder A doesn't contain the file directly below it, should it then look in other folders below it, or stop straight away?
  • If A doesn't have the file, but A\B does contain the file, do you want A to be included or excluded?
  1. filename is FolderArt.xmv
  2. No, there won't be any
  3. Assuming this is dependant on #2? If yes, this doesn't matter then.

Thanks.

Download this and drop it into the list in Preferences / Toolbars / Scripts:

(For more detail on installing it: How to use buttons and scripts from this forum )

You can then use it like this:

Script code for reference:

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "HasFolderArt";
	initData.version = "1.0";
	initData.copyright = "(c) 2018 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/this-type-of-search-possible/28558";
	initData.desc = "Adds a column that says if a folder contains a FolderArt.xmv file, which can be used for searching.";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var col = initData.AddColumn();
	col.name = "HasFolderArt";
	col.method = "OnHasFolderArt";
	col.label = "Has Folder Art";
	col.justify = "left";
	col.autogroup = true;
	col.match.push_back("Yes");
	col.match.push_back("No");
}


// Implement the HasFolderArt column
function OnHasFolderArt(scriptColData)
{
	if (!scriptColData.item.is_dir)
	{
		scriptColData.value = "";
		return;
	}

	if (DOpus.FSUtil.Exists(scriptColData.item.realpath + "\\FolderArt.xmv"))
	{
		scriptColData.value = "Yes";
	}
	else
	{
		scriptColData.value = "No";
	}
}
2 Likes

Wow. That is above and beyond. Will try it out. Thanks @Leo!

Works like a champ! Thanks again. Save me a few hours.

1 Like

Nice solution @Leo.

This kind of thing comes up every now and then. Would make a good generic script.

For when using a filter could we update it to accept a match string to the script column?

This would make mean the column does not work as a normal column. But would add some value in this scenario.

I don't think script columns can do that. They aren't told what the filter is looking for.

Might be a useful addition to support something like this.

For anyone finding this thread, here's a related thread which has some other methods of doing similar things.

The script I posted above is a good solution for some tasks, but the ones in the other thread may suit you better, depending on exactly what you need to do.

@Leo I am a brand new user, just bought the software about 10 minutes ago. During my trial period I made great use of this script. It saved me enough time that it convinced me to buy the software (along with lots of other reasons). I hope it's okay to dig up this old post, if that wasn't the correct course of action, I apologize.

I was wondering if this script could be tweaked a little bit? I have a feeling that what I want should be an easy tweak, but I am not a programmer and I couldn't figure it out for the life of me.

What I want to be able to do is locate folders that do not contain a certain file type. As an example, in my music directory, locate all folders that do not contain a .jpg file. Now, all of my album covers have different names so it would need to search with a wildcard, like *.jpg

Other than that, I want it to function exactly how the existing script functions.

TL;DR Can this script be changed to search for missing filetypes with various names instead of missing files with a specific name?

Thanks!

Easy enough:

HasFolderJpeg.js.txt (1.4 KB)

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.

var wild = DOpus.FSUtil.NewWild("*.(jpg|jpeg)", "f");

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "HasJPEG";
	initData.version = "1.0";
	initData.copyright = "(c) 2019 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/find-folders-that-do-not-have-a-specific-file/28558/11";
	initData.desc = "A column that says if a folder contains any JPG file directly below it, for use with searching.";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var col = initData.AddColumn();
	col.name = "HasJPEG";
	col.method = "OnHasJPEG";
	col.label = "Has JPEG";
	col.justify = "left";
	col.autogroup = true;
	col.match.push_back("Yes");
	col.match.push_back("No");
}


// Implement the HasJPEG column
function OnHasJPEG(scriptColData)
{
	if (!scriptColData.item.is_dir)
	{
		scriptColData.value = "";
		return;
	}

	var match = false;
	var dir = DOpus.FSUtil.ReadDir(scriptColData.item.realpath);

	while (!match && !dir.complete)
	{
		var item = dir.Next();
		if (item.is_dir)
		{
			continue;
		}
		if (wild.Match(item))
		{
			match = true;
		}
	}
	dir.Close();

	if (match)
	{
		scriptColData.value = "Yes";
	}
	else
	{
		scriptColData.value = "No";
	}
}
3 Likes

Perfecto! I assume that if I want to modify it to locate folders that don't contain .nfo files I would modify this line

var wild = DOpus.FSUtil.NewWild("*.(jpg|jpeg)", "f");

to

var wild = DOpus.FSUtil.NewWild("*.(nfo)", "f");

Thank you so much for doing that for me, this is going to come in very handy!

1 Like