Delete empty folders

hello can anyone help with a script that will detect all empty folders in the panel and delete them?

"Panel" as in the current folder?

How are you defining "empty"? Nothing at all in it? Zero bytes below it? Only folders containing other folders and no files (even if zero bytes)?

Do you want to look for folders directly below the starting point, or also ones in sub-folders under that?

1 Like

sorry yes the current directory i am in when i run the script and i want to search all subfolders as well. and by empty i mean folders with no content in them. i would assume that means 0 bytes but i dont know if that would stop it from deleting a folder with other empty folders inside.

Have a look here

You should be able to do it with a delete filter. See Size in Filter Clause Types and Filtered Operations for more general info.

If using Opus 13, the filter could use the new Folder Content clause to be more explicit about which folders it considers empty (e.g. so it keeps folders containing files that are all zero bytes, rather than consider them empty).

in the script that lets me move all files from folders and delete them i noticed at the end it does this function so it may also work.
looks like it just checks for folders with 0 file count

// Delete empty folders
	cmd.RunCommand('Delete FILE RECYCLE QUIET');
}

function FileCountRecursive(filePath) {
	var fileCount = 0;
	var folderEnum = fsu.ReadDir(filePath, "r");
	while (!folderEnum.complete) {
		var folderItem = folderEnum.Next;
		if (!folderItem.is_dir) {
			++fileCount;
		}
	}
	return fileCount;
}

Scripting is another option, certainly.

1 Like

Another option (the one that I've gone with) is to create a button with a link to the Remove Empty Directories (RED) app which focuses on precisely what its name suggests (but with certain user-configurable options): Remove Empty Directories (aka RED). I'd suggest using the v2.3 beta (which was released about 3 years ago and appears to be very stable).

1 Like