MrCreatoR Posted June 24, 2009 Share Posted June 24, 2009 (edited) directory depth of > 10 or lets say > 20 is very ununsual. Personally i think theres NO directory structure in the world going down 4710 stepsMaybe 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 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 - Maybe it's some kind of a bug? Edited June 24, 2009 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
KaFu Posted June 24, 2009 Author Share Posted June 24, 2009 Sooo, what do you think about this? expandcollapse popup#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 , 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 ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 24, 2009 Share Posted June 24, 2009 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 ...Ok, there is a limitation in many ways, but we do what we can P.SI 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 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now