Sign in to follow this  
Followers 0
trids

Drivespacetotal() - Drivespacefree()

7 posts in this topic

: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

Share this post


Link to post
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%.

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  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

Share this post


Link to post
Share on other sites

from command line

dir c: /s /a > directory.txt


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

dir c: /s /a > directory.txt

.. Thanks for the tip - nice workaround :whistle:

Share this post


Link to post
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
Sign in to follow this  
Followers 0