Jump to content

Recommended Posts

Posted

Hey,

I need a (simple) way to count all files in a directory AND it's subdirectories.

$d = FileFindFirstFile($tmp&"\*")
    While 1
    $dfile = FileFindNextFile($d)
    If @error Then ExitLoop
    If StringLeft($dfile,1) <> "." And StringLeft($dfile,1) <> ".." And StringLeft($dfile,1) <> "~" Then
    $counttemp = $counttemp +1
    Else
    EndIf
    WEnd

Already tried that, but this of course does not count files in subdirs(which's names are random!). On the other hand it is absolutely nesessary that the function does NOT count the subdirs itself.

Posted (edited)

Global $number = 0

$search = FileFindFirstFile("C:\*.*")

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $number += 1
WEnd

FileClose($search)

MsgBox(0,"", $number)

Should work :D

Hmm you need to count the files for all subdirectories i think!

Edited by Daniel W.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Posted

Maybe something like this...

$total = 0
_CountFilesRecursive("C:\some\folder")
MsgBox(0, "total", $total)

func _CountFilesRecursive($dir)
    $handle = FileFindFirstFile($dir & "\*.*")
    while 1
        $file = FileFindNextFile($handle)
        if @error then exitloop
        if StringInStr(FileGetAttrib($dir & "\" & $file), "D") and ($file <> "." or $file <> "..") then
            _CountFilesRecursive($dir & "\" & $file)
        else
            $total += 1
        endif
    wend
    FileClose($handle)
endfunc

-mu

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
×
×
  • Create New...