rejetto forum

a method to get folder size

rejetto · 18 · 37810

0 Members and 1 Guest are viewing this topic.

Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile
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
' ---------------------------------
' 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







Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile
you should tell something more if you want help


Offline LightBright

  • Occasional poster
  • *
    • Posts: 5
    • View Profile
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strWindowsdir & "\explorer.exe")
MsgBox("file size = " & f.size)


Offline r][m

  • Tireless poster
  • ****
    • Posts: 347
    • View Profile
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
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile

Hari

  • Guest
Attached the script for csv output


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
But then how can HFS be used to capture the output of that VBS script?


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile
by using the "out" parameter of {.exec.} command



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
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 18, 2011, 01:59:25 AM by raybob95 »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13521
    • View Profile
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

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Yeah that's the thing it runs every time the page loads.