Jump to content
Sign in to follow this  

Count files in directories

Recommended Posts


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

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.

Share this post

Link to post
Share on other sites

Global $number = 0

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

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


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]

Share this post

Link to post
Share on other sites

Maybe something like this...

$total = 0
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)
            $total += 1


Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...