Sign in to follow this  
Followers 0
AcidCorps

Building a FileFind Function (Yes another one)

3 posts in this topic

#include 
$Files = FileFind()
_ArrayDisplay($Files)

Func FileFind($s_Dir = @ScriptDir, $s_DirDeep = 333333, $s_Mask = '*.*')
;Declaring Variables    
Dim $s_Dirs[$s_DirDeep]
Local $n_DirCount = 0
Local $s_File
Local $s_Search
Local $s_TFile
Local $s_FileArray
Local $s_Filenames
Local $s_FileCount
Local $s_DirCount = 1
Local $s_Msg = 'Error'

;Format Dir if required
If StringRight($s_Dir, 1) - '\' Then $s_Dir = StringTrimRight($s_Dir, 1)

;Finding Files
$s_Dirs[$s_DirCount] = $s_Dir

If Not FileExists($s_Dir) Then Return 0

;Start Loop
While $s_DirCount > $n_DirCount
    
    $n_DirCount += 1
    $s_Search = FileFindFirstFile($s_Dirs[$n_DirCount] & '\*.*')
    
    While 1
        $s_File = FileFindNextFile($s_Search)
        If @error Then ExitLoop
        
        If $s_File = '.' Or $s_File = '..' Then ContinueLoop
        
        $s_TFile = $s_Dirs[$n_DirCount] & '\' & $s_File 
        
        If StringInStr(FilegetAttrib($s_TFile), 'D') Then
            $s_DirCount += 1
            $n_DirCount[$s_DirCount] = $s_TFile
        EndIf
    WEnd
    FileClose($s_Search)
    
    If StringInStr($s_Mask, ',', 2) Then
        $s_MaskArray = StringSplit($s_Mask, ',')
    Else
        Dim $s_MaskArray[2] = [1, $s_Mask]
    EndIf
    
    For $s_MaskCount = 1 To $s_MaskArray[0]
        $s_Search = FileFindFirstFile($s_Dirs[$n_DirCount] & '\' & $s_MaskArray[$s_MaskCount])
        If $s_Search = -1 Then ContinueLoop
        
        While 1
            $s_File = FileFindNextFile($s_Search)
            If @error Then ExitLoop
            If $s_File = '.' Or $s_File = '..' Then ContinueLoop
            
            $s_TFIle = $s_Dirs[$n_CirCount] & '\' & $s_File
            If Not StringInStr(FileGetAttrib($s_TFile), 'D') Then
                $s_FileCount += 1
                $s_FileNames & = $s_TFile & @LF
            EndIf
        WEnd
        FileClose($s_Search)
    Next
WEnd

$s_Filenames = StringTrimRight($s_Filenames, 1)
If $s_Filenames = '' Then Return 0
$s_FileArray = StringSplit($s_Filenames, @LF)

Return $s_FileArray
EndFunc

When I run the script I get an error

Line 42 (File "\Script"):

$n_DirCount[$s_DirCount] = $s_TFile

Error: Expected a "=" operator in assignment statement

the thing is even in the error box it shows a "=" in the assigment, this is not the first time I've gotten this message I just usually worked around it but I want to understand what I'm doing wrong

Share this post


Link to post
Share on other sites



Hi,

I dont think that autoit appreciate when you try to do array based operation on an integer variable.

$n_DirCount[$s_DirCount]

here $n_DirCount is an integer.

regards.


Iklim

Share this post


Link to post
Share on other sites

This seems to work, all I did was change the array that IKlim was talking about:

#include<array.au3>
$Files = FileFind()
_ArrayDisplay($Files)

Func FileFind($s_Dir = @ScriptDir, $s_DirDeep = 333333, $s_Mask = '*.*')
;Declaring Variables   
Dim $s_Dirs[$s_DirDeep]
Local $n_DirCount = 0
Local $s_File
Local $s_Search
Local $s_TFile
Local $s_FileArray
Local $s_Filenames
Local $s_FileCount
Local $s_DirCount = 1
Local $s_Msg = 'Error'
Local $newarray[2]

;Format Dir if required
If StringRight($s_Dir, 1) - '\' Then $s_Dir = StringTrimRight($s_Dir, 1)

;Finding Files
$s_Dirs[$s_DirCount] = $s_Dir

If Not FileExists($s_Dir) Then Return 0

;Start Loop
While $s_DirCount > $n_DirCount
   
    $n_DirCount += 1
    $s_Search = FileFindFirstFile($s_Dirs[$n_DirCount] & '\*.*')
   
    While 1
        $s_File = FileFindNextFile($s_Search)
        If @error Then ExitLoop
       
        If $s_File = '.' Or $s_File = '..' Then ContinueLoop
       
        $s_TFile = $s_Dirs[$n_DirCount] & '\' & $s_File
       
        If StringInStr(FilegetAttrib($s_TFile), 'D') Then
            $s_DirCount += 1
            ReDim $newarray[UBound($newarray) + 1]
            $newarray[$s_DirCount] = $s_TFile
        EndIf
    WEnd
    FileClose($s_Search)
   
    If StringInStr($s_Mask, ',', 2) Then
        $s_MaskArray = StringSplit($s_Mask, ',')
    Else
        Dim $s_MaskArray[2] = [1, $s_Mask]
    EndIf
   
    For $s_MaskCount = 1 To $s_MaskArray[0]
        $s_Search = FileFindFirstFile($s_Dirs[$n_DirCount] & '\' & $s_MaskArray[$s_MaskCount])
        If $s_Search = -1 Then ContinueLoop
       
        While 1
            $s_File = FileFindNextFile($s_Search)
            If @error Then ExitLoop
            If $s_File = '.' Or $s_File = '..' Then ContinueLoop
           
            $s_TFIle = $s_Dirs[$n_DirCount] & '\' & $s_File
            If Not StringInStr(FileGetAttrib($s_TFile), 'D') Then
                $s_FileCount += 1
                $s_FileNames &= $s_TFile & @LF
            EndIf
        WEnd
        FileClose($s_Search)
    Next
WEnd

$s_Filenames = StringTrimRight($s_Filenames, 1)
If $s_Filenames = '' Then Return 0
$s_FileArray = StringSplit($s_Filenames, @LF)

Return $s_FileArray
EndFunc

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