Jump to content

Recommended Posts

Posted

:evil: Okay .. I confess I misunderstood the helpfile on DriveSpaceTotal and DriveSpaceFree: I understood that the difference between these figures would yield the size of a folder B) ..

$sPath = "D:\temp\target\"
    $nSpaceTotal = DriveSpaceTotal($sPath)
    $nSpaceFree = DriveSpaceFree($sPath)
    $nSpaceUsed = $nSpaceTotal - $nSpaceFree
    msgbox (4096 + 32,"",$nSpaceTotal & @LF & $nSpaceFree & @LF & $nSpaceUsed)

However, the figures that are returned evidently apply only to the root of the path argument, regardless of the folder specified. I submit, though, that the helpfile conspired in my delusion :whistle: :

Remarks

DriveSpaceFree may even work when a complete directory path (that exists) is given.

Nevertheless .. if FileGetSize won't help either (the documentation says "Does not work on directories" .. then how does one cleverly find out the size of a folder??? :angry:

3.0.94.0 (unstable)

NT4

Posted

In AutoHotkey you can do it this way. I'm pretty sure you can do something similar AutoIt3 using its FindFirst/NextFile, but it takes a little bit more code:

FileSelectFolder, folder_name, C:\,, Choose a folder to analyze:
TotalSize = 0
Loop, %folder_name%\*.*,, 1
     TotalSize += %A_LoopFileSizeKB%
MsgBox, Total size in KB of "%folder_name%" is %TotalSize%.
  • Developers
Posted

This script uses the good old dir command and displays the totals for the given selection including the subdirs...

Just compile into xyz.exe and type the command: xyz c:\yourdir or xyz c:\yourdir\*.ext

(only tested in WinXP)

If $CmdLine[0] = 0 then exit
runwait('cmd /c Dir "' & $CmdLine[1]  & '" /s /x  > files.txt',"",@SW_HIDE)
$ifile = FileOpen("files.txt", 0)
; Check if file opened for reading OK
If $ifile = -1 Then
  MsgBox(0, "Error", "Unable to open: files.txt")
  Exit
EndIf
While 1
  $Fi_Rec = FileReadLine($iFile)
  If @error = -1 Then ExitLoop
  If StringInStr($Fi_Rec,"Total Files Listed:") Then
     MsgBox(4096,"Dirsize","Dirsize for selection:" & $CmdLine[1]  & @cr & FileReadLine($iFile)  & @cr & FileReadLine($iFile))
  endif
Wend

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Forgot to mention: My example above is recursive already, by means of the last parameter being 1. This means that all folders, regardless of how deeply nested, are included in the total size.

Edited by cmallett

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...