Jump to content

Drivespacetotal() - Drivespacefree()


trids
 Share

Recommended Posts

: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

Link to comment
Share on other sites

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%.
Link to comment
Share on other sites

  • Developers

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.
  :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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