Find folder size (conditionally) with LogParser


I was reading this post from Rahul a few days ago, and wondered if something similar could have been done (hopefully with less efforts) with LogParser… Well, it turned our that LogParser accepts a "-FS" switch which stands for File System as the input type, and if you run "logparser -h examples" you’ll have a few sample commands you can use as the basis of your scripts. And guess what? Here’s one of them:

Print the 10 largest files on the C: drive:
LogParser "SELECT TOP 10 * FROM C:\*.* ORDER BY Size DESC" -i:FS

I created a similar structure and put in there some sample images, just to have some files to count:

folder tree

So… here’s the script:

logparser "SELECT SUM(Size) FROM c:\temp\Rahul\*.* WHERE INDEX_OF(Path, ‘_wow’) > 0" -i:FS

And the output:

logparser output

5 images, 35.391 bytes each = 179.655 bytes… here we are! smile_regular

Carlo

Quote of the Day:
It is a great thing to start life with a small number of really good books which are your very own.
–Sir Arthur Conan Doyle

Comments (6)

  1. imRahulSoni says:

    That’s very cool!! Thanks’s for sharing it 🙂

  2. Anonymous says:

    LogParser is a sort of "hidden jewel" that not enough people know about.

    As of myself, I am aware it exists and that it is very powerful, but I rarely remember to resort to it – my bad, my bad!!!

    Lately I have much more busy with PowerShell… but until powershell gets installed on every machine, these other small and powerful tools come in very handy (I am thinking of machines owned by customers…).

    Thanks a for a lot of useful posts, man!!

  3. Anonymous says:

    LogParser is an awesome tool but for this particular task (finding large files, summing folder sizes etc.) I think i would go with PowerShell since it is far more flexible.

  4. Yes, sure… take this as a sort of "virtuosity exercise" with the tool 🙂

  5. Anonymous says:

    When I joint Microsoft and the EMEA Internet Dev Support Team in late 2004, I soon realized that I had

  6. Anonymous says:

    When I joint Microsoft and the EMEA Internet Dev Support Team in late 2004, I soon realized that I had