Jump to content

Udf _foldersize


trids
 Share

Recommended Posts

Iteration in one (DOS) command B) .. surprisingly fast :whistle:

Func _FolderSize($psFolder)
;Uses the DOS "dir" command to recursively collect all filenames
;in a folder and its children; then adds up the filesize for each one
;and returns the total.
Local $sFileList, $nFileList, $nTotalSize

    $sFileList = "C:\_FolderSize.LST"
    RunWait(@Comspec & " /C DIR """ & $psFolder & "*.*"" /s/b /A:-D > " & $sFileList,"", @SW_HIDE)
    
    $nFileList = FileOpen($sFileList, 0)  ;0=open
    if $nFileList = -1 then
      ;Couldn't open list of files in designated folder
        SetError(1) 
        Return 0
    endif

;Read the listfile, and determine file sizes, 
;writing name and size to CSV file
    $nTotalSize = 0
    While 1
        $sFilePathName = FileReadLine($nFileList)
        if @error = -1 then;EOF
            ExitLoop
        endif
        $nTotalSize = $nTotalSize + FileGetSize($sFilePathName)
    Wend

;Cleanup
    FileClose($nFileList)
#cs    
    FileDelete($sFileList)
#ce    
    Return $nTotalSize
EndFunc

Usage

;Example of call to UDF _FolderSize()
    $sFolder = @TempDir
    $nFolderSize = _FolderSize($sFolder)
    If @error then 
       ;failed
    Else
       Msgbox (4096 + 32,@ScriptName,"Size of " & $sFolder & " = " & $nFolderSize )
    Endif
Exit
Edited by trids
Link to comment
Share on other sites

  • 7 years later...

Hi,

there is already DirGetSize and you can try to get rid off saving the info of files into a file.

Something like this

Func _FolderSize1($folderPath)
Local $tempWorkDir = @WorkingDir
FileChangeDir($folderPath)
Local $nTotalSize = 0
Local $command = 'dir "' & $folderPath & '" "*.*" /s/b /A:-D'
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
  $text &= StdoutRead($Pid, False, False)
  If @error Then ExitLoop
  Sleep(10)
WEnd
Local $re = StringSplit(StringStripCR($text), @LF, 2)
For $i = 0 To UBound($re) - 1
  $nTotalSize += FileGetSize($re[$i])
Next
FileChangeDir($tempWorkDir)
Return $nTotalSize / 1048576 /2
EndFunc   ;==>_FolderSize1

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

The thread was started in 2004! :graduated:

This interface is crazy! Mad, Mad, Mad, Loca, Loca, Louca! ;)

If you do not pay attention to the date, then you end up responding ...

João Carlos.

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

This interface is crazy! Mad, Mad, Mad, Loca, Loca, Louca! :graduated:

If you do not pay attention to the date, then you end up responding ...

João Carlos.

That makes no sense, of course you have to pay attention to the date, that's the same as in EVERY forum. I don't see how you're going to know when it was posted if you don't look at the post date.

Were you expecting the forum software to warn you that the post is x amount of days/weeks/months/years old without you having to do anything?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That makes no sense, of course you have to pay attention to the date, that's the same as in EVERY forum. I don't see how you're going to know when it was posted if you don't look at the post date.

Were you expecting the forum software to warn you that the post is x amount of days/weeks/months/years old without you having to do anything?

I see that you are very upset with my answer, you are the author of this interface?

Perhaps the just Xenobiologist did as many others do: respond what you see on the first page, regardless of the date of the posting!

But do not be offended: this forum was not meant to deal with issues of this category! Do not wait my return :graduated:

João Carlos.

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

That makes no sense, of course you have to pay attention to the date, that's the same as in EVERY forum. I don't see how you're going to know when it was posted if you don't look at the post date.

Were you expecting the forum software to warn you that the post is x amount of days/weeks/months/years old without you having to do anything?

Actually, in my view it makes perfect sense. The date is in a light gray text that is not easy to discern from the bright white background.

I can see how easy it would be for someone to miss it when reply to the message.

Especially if your eyesight isn't as good as it used to be "Like mine".

In fact, I've "almost" done it a few times myself.

In most cases I reply to recent posts so that date is of no importance.

However, when I've been searching for a solution to a problem I've gone to ask the poster a question and only just cuaght myself in time. :graduated:

And that is only because I check my replies before sending.

Link to comment
Share on other sites

The thread was started in 2004! :graduated:

Br,

UEZ ;)

That's what is going to happen if you are to blind to see what you are clicking at.

I thought I clicked next, but I pushed the button to get to the end (which is the first) page of all threads in that particular forum, I suppose.

Anyhow, I need to visit Autoit forums a bit more in the future :-)

Mega

Besides, you all were right, I didn't recognize that the post was so old.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I sometimes go into the online users list just to see what posts are out there that I haven't run into before. Most of the ones that seem interesting are the ones from years ago being looked at by "Guests". I have to make sure what I'm looking at rather responding to them :graduated:

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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