Sign in to follow this  
Followers 0
Tiger

Count the files

8 posts in this topic

How can I count the files in a directory?


My UDFs:- _RegEnumKey

Share this post


Link to post
Share on other sites



Try this:

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
$i = 0

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    $i = $i + 1 
WEnd
MsgBox (0, "Files", "There are " &$i&" files and folders in the directory.")
; Close the search handle
FileClose($search)

Share this post


Link to post
Share on other sites

check out _FileListToArray in file.au3

#include <File.au3>

_FileListToArray ( $sPath [, $sFilter [, $iFlag]] )

Optional: specifies wheather to return files folders or both

$iFlag=0(Default) Return both files and folders

$iFlag=1 Return files only <---great filter if you want files only

$iFlag=2 Return Folders only

The array returned is one-dimensional and is made up as follows:

$array[0] = Number of Files\Folders returned <------what you want


Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of — shhh — extensions!

Share this post


Link to post
Share on other sites

You can also use DirGetSize() function.

If you use the extended mode then the array returned from this function is a single dimension array containing the following elements:

$array[0] = Size

$array[1] = Files count

$array[2] = Dirs Count

#include <Array.au3>

$size = DirGetSize(@DesktopDir, 1)
_ArrayDisplay($size, 'Files')

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Thanks people. I test it today.


My UDFs:- _RegEnumKey

Share this post


Link to post
Share on other sites

If looking for all files shouldn't we use '*' instead of '*.*' ?

Share this post


Link to post
Share on other sites

If looking for all files shouldn't we use '*' instead of '*.*' ?

I think that using *.* is more “secure”, because when you use *.* it search for all files with any extansion.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Yes, but what if you have 'blah' with no extension, several programs create files like that... when installing iPod Linux you need the file called 'start' with no extension... I think that was hmsSurprise's point...

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