Filter Empty subfolders

Hi,

I’m developing a relevance analysis that will report the content of D:\ Drive.

I’ve the following code at the moment:

((pathnames whose ( it does not contain "Recycle.Bin" ) of it, (sum of sizes of descendants of it) /1024/1024) of folders of folder "D:\") 

I need to have a better performance, because it sometimes takes until 1min to scan the content.
Because of that I’m trying to filter empty folders or cero size.
I’ve something like this:

((pathnames whose ( it does not contain "Recycle.Bin" ) of it as string, ((sum whose (sum of it as string does not equal "0" ) of sizes of descendants of it) /1024/1024)as string & "MB") of folders of folder "D:\")

It code doesn’t work.

I also try with:

((pathnames whose ( it does not contain "Recycle.Bin" AND (((sum of sizes of descendants of folders of folder it)/1024/1024) does not equal 0 ) ) of it as string, ((sum of sizes of descendants of it) /1024/1024)as string & "MB") of folders of folder "D:\")

But still it doesn’t works as I need.

Any suggestions?

If my understanding of your issue is correct I do not think that filtering out empty folders will improve the speed of your query.

The cost of gathering the size of an empty folder to see if you should exclude it is the same as the cost of gathering the size of an empty folder and adding it to your sum.

The performance penalty isn’t due to the number of empty folders you have – it’ll be due to the number of files covered by the query.

Overall this is just going to be a slow query due to the potential number of files you are hitting on the disk.

That being said – if you really just want to filter out empty folders you can do this…

(((pathnames whose ( it does not contain "Recycle.Bin" ) of it, (sum of sizes of descendants of it) /1024/1024) of folders of folder "D:\")) whose (item 1 of it != 0)

adding a filter –

item 1 of it !=0

Will not show any folders that have a reported descendant size of 0

Yes, that’s correct.

Could be another approach to improve the speed and get the same result using just an analysis?

I might just use your analysis as it is but tell it to run only once a day/once a week

@strawgate is correct that this query is going to be slow no matter what.

What is it that you are trying to accomplish with this query? There might be some better ways to optimize this depending on what you are trying to achieve. For instance, could all files under a certain size be ignored?

One of the first problems you have is that you are not actually excluding things in the Recycle bin. You are only excluding them in the report of the pathnames of the files.

This should be slightly faster:

(pathnames of it, sum of sizes whose(it > 4096) of descendants of it) of folders whose(name of it as lowercase does not end with "recycle.bin") of folders "D:"

This is still a bad idea and I would not recommend it.

Also, you CANNOT use this in Fixlet/Task relevance. You should ONLY use this in an analysis property with a report time of once per 12 hours or less often.

One huge issue with this query is it is impossible to predict how long this will take. It could take a VERY long time on some systems. You would probably be better off running something on the command line to generate a report on a periodic basis and then read that report with relevance.

1 Like

Thanks @jgstew what I need to get is the following detail:

For example:

    D:
    |
    |-----Folder 1 ---- 5M
    |     |   
    |     |         
    |     Folder 1a -------3Mb
    |     FileA----------2Mb
    |
    |-------Folder2 ---- 500M
    |
    |-------Folder 3 ---- 0M

The analysis needs to display
The content of the first folder and the first level of content, I mean Folder 1a and FileA. Also I should show the size of folder2 and its content, Folder 3 should be no shown.

As I’m not very familiar with relevance I’m trying to go step by step.

Also I would think that a better approach could be run a vbs script via fixlet on the endpoints that outputs the result to a file and the use an analysis to get the result, but I just wanted to avoid to run a fixlet.

What if the total size of a folder and all of it’s contents are less than 1MB? Can that be ignored, or do you want that to be included?

Try this:

(pathnames of it, sum of sizes whose(it > 4096) of descendants of it) whose( item 1 of it > (1024*1024) ) of folders whose(name of it as lowercase does not end with "recycle.bin") of folders "D:"

Yes, they can be ignored

Try this:

(item 0 of it, (it as string & " MB") of ( (significant digits 2 of item 1 of it) / (1024*1024) ) ) of (pathname of it, sum of sizes whose(it > 4096) of descendants of it) whose( item 1 of it > (1800000) ) of folders whose(name of it as lowercase does not end with "recycle.bin") of folders "D:"

Related: https://bigfix.me/relevance/details/3003610

I’m getting the following error on some endpoints:

The expression could not be evaluated: class IllegalFileName

No sure what it means, I’ve been no able to reproduce the issue on the endpoints that I have access.

This is because you are accessing all files in those folders. If any file has a filename that contains unicode or other odd characters, you will get this error.

There isn’t a way around this as far as I know.

Related:

Good to know. So this approach is useless.
I don’t understand why IEM relevance can provide a suitable way to work with it, we have to use external options in order to get the information.
Also I check directly with IEM Support and they don’t provide support for custom content.

This forum is the support for custom content. Otherwise you would have to pay for consulting through AVP, Professional Services, or elsewhere.

You can get the info you require with BigFix, just not with Relevance.

The way you are using relevance is a bad idea in general. I think that is why this is considered mostly a non-issue.

Try this to see if it works:

(item 0 of it, (it as string & " MB") of ( (significant digits 2 of item 1 of it) / (1024*1024) ) ) of (pathname of it | "<Error>", sum of sizes whose(it > 4096) of descendants whose(exists name of it) of it) whose( item 1 of it > (1800000) ) of folders whose(exists pathname of it AND name of it as lowercase does not end with "recycle.bin") of folders "D:"