Jump to content

_DirGetSizeEx


KaFu
 Share

Recommended Posts

directory depth of > 10 or lets say > 20 is very ununsual. Personally i think theres NO directory structure in the world going down 4710 steps

Maybe there isn't, maybe there is, but take that risk (that it can crash, even theoretically?)

You mentioned that the files/folders count is wrong? Couldn't verfify that, what did you do test assume this?

The same example from your first post :D

You can fix it by adding & "\" to $sPath & $sNext in FileGetAttrib part.

And here is a strange behaviour - check this example:

$sAttrib = FileGetAttrib(@AppDataDir & "\Macromedia\Flash Player\#SharedObjects\DMBCTE22\localhost\Program Files ")
;~ $sAttrib = FileGetAttrib(@AppDataDir & "\Macromedia\Flash Player\#SharedObjects\DMBCTE22\localhost\Program Files \")
ConsoleWrite($sAttrib & @CRLF)

I got the folder there ("Program Files ") wich is having space at the end, and i can not rename it, but FileGetAttrib (or even FileExists) returns "" (or 0 with FileExists) if i don't use trailing slash :D - Maybe it's some kind of a bug?

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Sooo, what do you think about this?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         KaFu
 Script Name, Version and Date: _DirGetSizeEx v04 (09-Jan-22)

 Script Function:
    _DirGetSizeEx, a replacement for DirGetSize()
    UDF using AU native functions only. Faster than DirGetSize() in the inital run on XP, slower in a repeated run, DirGetSize seems to cache the result.
    Change $Path between tests to seem what I mean.

    DirGetSize can not be interrupted / stopped, that's the main reason I coded this UDF

    Function returns an array
    $array[0] = Bytes
    $array[1] = File Count
    $array[2] = Folder Count

    @error = 1, max. recursion level of 5100 exceeded, directory structure too deep

    On Vista DirGetSize seems to be much faster than on XP, thus if you're only into speed use something like:

    if @OSVersion <> "WIN_VISTA" Then
        $aResult = _DirGetSizeEx($Path)
    Else
        $aResult = DirGetSize($Path)
    EndIf

    But keep in mind, main advantage of _DirGetSizeEx is that during runtime you can easily implement a progress count or interrupt the function with
    a global variable (like I do in SMF, just define a bool something like $running = true and switch it with WM_COMMAND)

#ce ----------------------------------------------------------------------------

Dim $Path = @AppDataDir

$begin = TimerInit()
$a_DirGetSize = DirGetSize($Path, 1)
$dif_DirGetSize = round(TimerDiff($begin),0)

$begin = TimerInit()
$a_DirGetSizeEx = _DirGetSizeEx($Path)  ; <= recommended
MsgBox(0,"",@error)
$dif_DirGetSizeEx = round(TimerDiff($begin),0)

MsgBox(0, 'Comparison DirGetSize() vs _DirGetSizeEx', '' _
        & 'DirGetSize()' & @crlf & 'Time: ' & $dif_DirGetSize & @crlf &  'Bytes: ' & $a_DirGetSize[0] & @crlf & 'File Count: ' & $a_DirGetSize[1] & @CRLF & 'Folder Count: ' & $a_DirGetSize[2] & @CRLF & @CRLF _
        & '_DirGetSizeEx()' & @crlf & 'Time: ' & $dif_DirGetSizeEx & @crlf & 'Bytes: ' & $a_DirGetSizeEx[0] & @crlf & 'File Count: ' & $a_DirGetSizeEx[1] & @CRLF & 'Folder Count: ' & $a_DirGetSizeEx[2])

Func _DirGetSizeEx($sPath = @ScriptDir)
    Local $sSearch, $aResult[3], $aResult_sub[3]
    if Not IsDeclared("iDirGetSizeExRecursionLevel") then
        Global $iDirGetSizeExRecursionLevel = 1
    Else
        $iDirGetSizeExRecursionLevel += 1
    endif
    if $iDirGetSizeExRecursionLevel = 5099 Then
        SetError(1)
        Return
    endif

    If StringRight($sPath, 1) <> "\" Then $sPath &= "\" ; Ensure $sPath has a trailing slash
    $sSearch = FileFindFirstFile($sPath & "*.*")
    While 1
        $sNext = FileFindNextFile($sSearch) ; check if next file can be found, otherwise exit loop
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($sPath & $sNext & "\"), "D") Then
            $aResult[2] += 1
            $aResult_sub = _DirGetSizeEx($sPath & $sNext)
            if @error then
                SetError(@error)
                Return
            endif
            $aResult[0] += $aResult_sub[0]
            $aResult[1] += $aResult_sub[1]
            $aResult[2] += $aResult_sub[2]
        Else
            $aResult[1] += 1
            $aResult[0] += FileGetSize($sPath & $sNext)
        EndIf
    WEnd
    FileClose($sSearch)
    Return $aResult
EndFunc   ;==>_DirGetSizeEx

Speaking of theoretical errors... of course I want to defend my UDF :D , but a here's a real question. You propose to store the file information in a string and then return a respective stringsplit array. I did some research on max. string length and came up with the 2GB hard limit, but a practical limit of ~100MB. Assuming a medium filename length of 40 this means 250.000 files, that would be the limit your script errors out... though I'm of course also not sure about the behavior of array's, hard limited by elements to 16.000.000 entries, going beyond the 100MB... guess it might be similar to the (practical) string size limitation. This definitly's worth more research, as it will also have an impact on the _FileListToArray() function! Breaking the 250.000 file limit is not to hard :D ...

Link to comment
Share on other sites

Sooo, what do you think about this?

Good workaround, but i can not understand why you don't want to use loops instead of recursive function calls?

Speaking of theoretical errors... of course I want to defend my UDF ;) , but a here's a real question. You propose to store the file information in a string and then return a respective stringsplit array. I did some research on max. string length and came up with the 2GB hard limit, but a practical limit of ~100MB. Assuming a medium filename length of 40 this means 250.000 files, that would be the limit your script errors out... though I'm of course also not sure about the behavior of array's, hard limited by elements to 16.000.000 entries, going beyond the 100MB... guess it might be similar to the (practical) string size limitation. This definitly's worth more research, as it will also have an impact on the _FileListToArray() function! Breaking the 250.000 file limit is not to hard :D ...

Ok, there is a limitation in many ways, but we do what we can :P

P.S

I only proposed a small solution, and besides that - the function that i posted works the same as the original, it can accept the same flags and options + some more :D

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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