ioliver Posted August 1, 2005 Posted August 1, 2005 Is there a way to find Directories, like there's a way to find Files using FileFindFirstFile()? What I need to do is find the size of all the directories in the 'Documents and Settings' folder. Thanks for any help. Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
this-is-me Posted August 1, 2005 Posted August 1, 2005 If StringInStr(FileGetAttrib($filename), "D") Then It's a directory. Who else would I be?
Helge Posted August 1, 2005 Posted August 1, 2005 (edited) Do a normal search using the FileFind*-functions, and then use FileGetAttrib()and check if the returned value contains a "D". If it does, it is a directory.Edit : Typo..plus..doh ! Edited August 1, 2005 by Helge
blindwig Posted August 1, 2005 Posted August 1, 2005 (edited) You could use my _GetTreeSize function as a reference. It takes a path as a parameter, and returns a 2d array list of directories and their total size.expandcollapse popupFunc _GetTreeSize($sPath) Dim $aFolders[100][2], $iSize _ProgressCreate(__FileTruncPath($sPath, 45), '', 'Directory Size') $aFolders[0][0]=1 $aFolders[1][0]=$sPath $iSize=__GetTreeSize($sPath, 0, 100, $aFolders) $aFolders[1][1]=$iSize ReDim $aFolders[$aFolders[0][0] + 1][2] _ProgressDelete() Return $aFolders EndFunc Func __GetTreeSize($sPath, $fCurPer, $fMaxPer, ByRef $aFolders) ;Get a list of all the folders, and a count of total file size Local $aFolder[100], $hSearch_All=FileFindFirstFile($sPath & '\*'), $iTotalSize=0 If $hSearch_All <> -1 Then $sFileName = FileFindNextFile($hSearch_All) While Not @error If _FileIsDir($sPath & '\' & $sFileName) Then If $sFileName <> '.' And $sFileName <> '..' Then $aFolder[0] = $aFolder[0] + 1 If $aFolder[0] >= UBound($aFolder) Then ReDim $aFolder[$aFolder[0] + 100] $aFolder[$aFolder[0]] = $sFileName EndIf Else $iTotalSize = $iTotalSize + FileGetSize($sPath & '\' & $sFileName) EndIf $sFileName = FileFindNextFile($hSearch_All) WEnd EndIf FileClose($hSearch_All) ReDim $aFolder[$aFolder[0] + 1] ;recurse into each folder Local $i, $fSlice = $fMaxPer / $aFolder[0], $fNewPer, $iDirSize, $iParentIndex For $i = 1 To $aFolder[0] $fNewPer = $fCurPer + $fSlice * ($i - 1) $aFolders[0][0] = $aFolders[0][0] + 1 If $aFolders[0][0] >= UBound($aFolders) Then ReDim $aFolders[$aFolders[0][0] * 2][2] $iNodePtr = $aFolders[0][0] $iDirSize = __GetTreeSize($sPath & '\' & $aFolder[$i], $fNewPer, $fSlice, $aFolders) $aFolders[$iNodePtr][0] = $sPath & '\' & $aFolder[$i] $aFolders[$iNodePtr][1] = $iDirSize $iTotalSize = $iTotalSize + $iDirSize Next _ProgressUpdate($fCurPer + $fMaxPer, __FileTruncPath($sPath, 60)) Return $iTotalSize EndFuncIt uses my progress bars, get them here or just remove those lines.It also uses my _FileIsDir() and _FileTruncPath() functions:expandcollapse popup;=============================================================================== ; ; Function Name: _FileIsDir ; Description: Returns true or false weather given file is a directory or not ; Parameter(s): $Path ; Requirement(s): ; Return Value(s): 0 = not a directory or does not exist, 1 = file exists and is a directory ; Author(s): Mike Ratzlaff <mike@ratzlaff.org> ; Revision: 20050623A ; ;=============================================================================== ; Func _FileIsDir($Path) ;This function checkes to see if $FileName exists and if it is a Directory If StringInStr(FileGetAttrib($Path), 'D') Then Return 1 Return 0 EndFunc ;==>_FileIsDir ;Truncates $sPath so that its length is <= $iSize Func _FileTruncPath($sPath, $iSize) ;split file from path Local $iSplit = StringInStr($sPath, '\', 0, -1) If $iSplit Then $sFile = StringMid($sPath, $iSplit) $sPath = StringLeft($sPath, $iSplit - 1) Else $sFile = $sPath $sPath = '' EndIf ;truncate and return new path Local $iPath = StringLen($sPath), $iFile = StringLen($sFile) If $iPath + $iFile <= $iSize Then Return $sPath & $sFile ElseIf $iFile > $iSize - 3 Then Return '...' & StringRight($sFile, $iSize - 3) Else Return StringLeft($sPath, $iSize - 3 - $iFile) & '...' & $sFile EndIf EndFunc Edited August 1, 2005 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
ioliver Posted August 1, 2005 Author Posted August 1, 2005 Thanks for all the suggestions. I'll try them out on tomorrow. I really appricate all the help. Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
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