Jump to content

Count Files


PcExpert
 Share

Recommended Posts

No offence but this is a kind of hilarious question from someone with your kind of nick :P

Anyhow, modify the sample provided in the help file for FileFindNextFile and you should be set. If you want to filter out the folders you could do so by checking the result from FileGetAttrib.

Happy coding :)

Link to comment
Share on other sites

;change the working directory
FileChangeDir( ".\temp" )

;get the first file
$search = FileFindFirstFile( "*.*" )

If $search = -1 Then
    MsgBox( 0, "ERROR!", "There are no files or could not connect to remote directory" )
EndIf

Dim $fileCount = 0

While 1
    $file = FileFindNextFile( $search )
    
    If @error Then
        ExitLoop
    EndIf
    If StringInStr( FileGetAttrib( $file ), "D" ) == 0 Then
        $fileCount += 1
    EndIf
WEnd

MsgBox( 0, "File Count", "Found " & $fileCount & " files." )

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

with 219 posts, i would think this was an easy one ????

#Include <File.au3>

$FileList=_FileListToArray(@DesktopDir, "*.*", 1)
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

MsgBox(64,"File Count", "Files in folder = " & $FileList[0])

8)

Quantity of Posts <> Knowledge of Autoit

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Hi,

Is it possible to count the number of files that are in a specified directory?

Thanks!

Look at the extended mode of DirGetSize().

$retArray = DirGetSize("C:\",1)

$nFiles = $retArray[1]
$nDirs = $retArray[2]

BTW: Think about error checking!! See help file sample.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Hi @Kurt,

Nice pointer to the DirGetSize. :)

I did not know that one, so I guess I'm still learning :P

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