Sign in to follow this  
Followers 0
PcExpert

Count Files

9 posts in this topic

Hi,

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

Thanks!

Share this post


Link to post
Share on other sites



$search=FilefindFirstFile("C:\dir\*.txt")

while 1

$file = FileFindNextFile($search)

if @error then exitloop

$countfiles += 1

wend

fileclose($search)

this counts all *.txt in c:\dir


SYS 64738

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Quantity of Posts <> Knowledge of Autoit

Quantity of Posts = Knowledge of Autoit's Help File

8)


NEWHeader1.png

Share this post


Link to post
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 *

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  
Followers 0