gritts
gritts

Reputation: 185

Attempting to use a SUB-SELECT within logparser to retrieve folder information

My end goal is to return data using log parser in a table similar to this

PATH      QTY       SIZE(KB)
C:\Path\dir     1200         150223

I can picture the query in my mind but I think I am missing something. (It's probably obvious). Here is my query as I have now:

C:\scripts>logparser -i:fs "SELECT f.* FROM (SELECT path FROM C:\DOWNLOADS\*.* WHERE ATTRIBUTES LIKE 'D%') f"

I receive this error: "Error: Syntax Error: : expecting FROM keyword instead of token '*'"

If I change my code a bit to the following, I get another curious error...

C:\scripts>logparser -i:fs "SELECT * FROM (SELECT path FROM C:\DOWNLOADS\*.* WHERE ATTRIBUTES LIKE 'D%')"

The error I receive is: "Cannot open : Error searching for files in folder C:\scripts(SELECT path FROM C:\DOWNLOADS: The filename, directory name, or volume label syntax is incorrect.

I'd like to return the size of the different sub directories below the c:\downloads path. I would adjust the wildcards to further narrow my results.

EDIT - More info I am hoping to return data from a structure similar to this:

TopFolder
|_SubFolder
| |_SubSubFolder1
| |_SubSubFolder2
| |_SubSubFolder3
|_OtherFolder

Return a table or some form of data like this:

_FolderName___Qty____AvgSize____MaxSize____MinSize
SubSubFolder1  250    334533      45000     445
SubSubFolder2  123     4443       2233      344
....

Upvotes: 1

Views: 2696

Answers (2)

gritts
gritts

Reputation: 185

Taking the information provided by @Gabriele I came up with the following logparser query which fits my needs...

logparser "select EXTRACT_PREFIX(Path,2,'\') as FolderName,Count() AS ItemCount,DIV(sum(size),1024) as KBSize from c:\downloads*. WHERE Attributes NOT LIKE 'D%' group by FolderName HAVING ItemCount > 1" -i:fs

My end goal is to collect stats on network folders populated by automated processes to track progress. The "c:\downloads" source would be changed for another source.

Upvotes: 0

Gabriele Giuseppini
Gabriele Giuseppini

Reputation: 1581

Well, first of all LogParser does not support nested SELECT's. This said, it's not clear why you need a sub-select. If you want to limit the depth of the directory search to 2, for example, then you can use '-recurse:2'. On the other hand, if you want to sum up all files below a directory, you need to SELECT SUM(Size) and GROUP BY with EXTRACT_PREFIX, specifying the level; for example:

SELECT EXTRACT_PREFIX(Path, 2, '\\') AS MyFolder, SUM(Size)
FROM C:\Downloads\*.*
GROUP BY MyFolder

Upvotes: 2

Related Questions