rejetto forum
Software => HFS ~ HTTP File Server => F.A.Q.s => Topic started by: rejetto on January 27, 2009, 10: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
[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. ;)
-
' ---------------------------------
' 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
-
I can't seem to get this to work
-
you should tell something more if you want help
-
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strWindowsdir & "\explorer.exe")
MsgBox("file size = " & f.size)
-
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?
-
i guess it's a .vbs script...?
-
Attached the script for csv output
-
But then how can HFS be used to capture the output of that VBS script?
-
by using the "out" parameter of {.exec.} command
-
Can you give me an example?
-
{.exec|ipconfig|out=#x.}
{.^#x.}
-
I GOT IT !!!!!! I'm not sure if this slows down the page load though....
Under [folder=file], put
{.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
{.if|{.^foldersize.}|{:{.^foldersize.}:}|{:%item-size%:}.}
:)
-
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
-
Yeah that's the thing it runs every time the page loads.
-
that's ok only if you have few files
-
It has nothing to do with files...? The script is only run for folders!
-
eh, but the time it takes depends on the number of files inside the folder. Isn't it so?