Author Topic: a method to get folder size  (Read 17642 times)

0 Members and 1 Guest are viewing this topic.

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
a method to get folder size
« on: January 27, 2009, 04:09:24 AM »
Hello, i came to this idea

ABSTRACT:
method to display the folder size instead of just folder.

LIMITATIONS:
1. It works only for real folders.
2. it won't care of files/folders filter that may actually reduce the stuff shown by your HFS.
3. This is thought essentially for large folders, that you must decide when the size should be refreshed. It's not fully automatic.

METHOD:

step 1. make a batch file like this

FOR %%s IN ("C:\music";"C:\my other folder")
DO du.exe -m -s %%s > %%s\foldersize & attrib +h %%s\foldersize

you can find du.exe in a package at http://unxutils.sourceforge.net/
(attached at bottom for your convenience)

step 2. put this in the diff template of the root, in HFS

Code: [Select]
[folder]
{.$item start.}
<td align='center'>
{.set|size|{.load|%item-resource%\foldersize.}.}
{.if|{.^size.}|{.substring|| |{.^size.}.} MB
|<i>folder</i>.}
<td align='right'>%item-modified%<td align='right'>%item-dl-count%

CONCLUSIONS:
i'm not actually using this, but i thought it would be good to share it, and maybe you can improve it. ;)

Hari

  • Guest
Re: a method to get folder size
« Reply #1 on: June 04, 2009, 01:08:42 AM »
' ---------------------------------
' Hariprasad Radhakrishnan
' hradhakrishnan@gmail.com
' Save script as folder.vbs
' Run script from cmd prompt C:\Scripts\cscript folder.vbs >FolderSize.txt  OR
' Run script from cmd prompt C:\Scripts\cscript folder.vbs  OR
'----------------------------------


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSubfolders = objWMIService.ExecQuery _
 ("ASSOCIATORS OF {Win32_Directory.Name='C:\'} " _
 & "WHERE AssocClass = Win32_Subdirectory " _
 & "ResultRole = PartComponent")

For Each objFolder in colSubfolders
'Loop Begins

'Echo Folder Name
 Wscript.Echo objFolder.Name
On Error Resume Next

'Pass Folder Name from WMI to FSO - Hari

objfsoFolder = "" & objFolder.Name & ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objfsoFolder)

'Covert objFolder size from bytes to GB
FolderSizeGB = formatnumber(objFolder.Size / (1024 * 1024 * 1024),2)

'Echo foldersize
Wscript.Echo "Folder Size = " & FolderSizeGB & " GB"

'Wscript.Echo "Folder Size = " & objFolder.Size & " Bytes"

'Counter for Number of Folders
Fcount=Fcount+1

Next
'Loop Ends

'Echo Total Folder Count
Wscript.Echo "Total Folders:  " & Fcount





Rygrass

  • Guest
Re: a method to get folder size
« Reply #2 on: May 09, 2010, 01:06:05 AM »
I can't seem to get this to work

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: a method to get folder size
« Reply #3 on: May 10, 2010, 09:46:10 AM »
you should tell something more if you want help

Offline LightBright

  • Occasional poster
  • *
  • Posts: 5
    • View Profile
Re: a method to get folder size
« Reply #4 on: July 27, 2010, 02:08:22 PM »
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strWindowsdir & "\explorer.exe")
MsgBox("file size = " & f.size)

Offline r][m

  • Insane poster
  • *****
  • Posts: 347
    • View Profile
Re: a method to get folder size
« Reply #5 on: July 29, 2010, 07:22:55 AM »
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strWindowsdir & "\explorer.exe")
MsgBox("file size = " & f.size)
@ LightBright
Could you give example about how and where to use this with HFS?

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: a method to get folder size
« Reply #6 on: July 30, 2010, 06:57:50 AM »
i guess it's a .vbs script...?

Hari

  • Guest
Re: a method to get folder size
« Reply #7 on: October 11, 2010, 07:37:49 AM »
Attached the script for csv output

Offline raybob

  • Insane poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: a method to get folder size
« Reply #8 on: August 09, 2011, 08:36:48 PM »
But then how can HFS be used to capture the output of that VBS script?

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: a method to get folder size
« Reply #9 on: August 22, 2011, 12:44:27 PM »
by using the "out" parameter of {.exec.} command

Offline raybob

  • Insane poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: a method to get folder size
« Reply #10 on: September 18, 2011, 10:05:12 AM »
Can you give me an example?

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: a method to get folder size
« Reply #11 on: October 04, 2011, 03:42:44 AM »
{.exec|ipconfig|out=#x.}
{.^#x.}

Offline raybob

  • Insane poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: a method to get folder size
« Reply #12 on: October 17, 2011, 07:50:15 PM »
I GOT IT !!!!!!   I'm not sure if this slows down the page load though....

Under [folder=file], put

Code: [Select]
{.if not|{.=|%item-size%|0.}|{:
{.set|foldersize|.}
{.set|vfsdir|{.vfs to disk|%url%%item-name%.}.}
{.save|C:\foldersize.bat|
@D:
@cd "{.^vfsdir.}"
@For /F "tokens=*" %%a IN ('"dir /s /-c {.no pipe||.} find "bytes" {.no pipe||.} find /v "free""') do @Set summaryout=%%a
@For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
@Set sizeout=%sizeout:bytes=%
@Set sizeout=%sizeout: =%
@Echo %sizeout%
.}
{.exec|C:\foldersize.bat|out=sizeresult.}{.set|foldersize|{.round|{.div|{.div|{.^sizeresult.}|1024.}|1024.}|2.} {.if|{.^sizeresult.}|MB.}.}
:}.}

and then under the size column put

Code: [Select]
{.if|{.^foldersize.}|{:{.^foldersize.}:}|{:%item-size%:}.}

  :)
« Last Edit: October 17, 2011, 07:59:25 PM by raybob95 »

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: a method to get folder size
« Reply #13 on: October 18, 2011, 07:28:34 AM »
but... is this script meant to run every time i load the page?


a side note about scripting. You wrote
{.if not|{.=|%item-size%|0.}|
since 0 is considered false, then this is equivalent to
{.if not|{.not|%item-size%.}|
that is equivalent to
{.if|%item-size%|
that's nice and lighter

Offline raybob

  • Insane poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: a method to get folder size
« Reply #14 on: October 18, 2011, 01:31:52 PM »
Yeah that's the thing it runs every time the page loads.