Jump to content

How can get all files of a directory and the subdirectory?


 Share

Recommended Posts

This is my code.Why it's only get the first every subdirectory?

Global $List[1]=[0]
Func FileListToArray($Dir)
    Dim $FilePath,$FilesList,$Files,$i
    $FilesList=_FileListToArray($Dir)
    If (Not IsArray($FilesList)) and (@Error=1) Then
        MsgBox (0,"","No Files\Folders Found.")
        Return 
    EndIf
    $Files=_FileListToArray($Dir,"*",1)
    If IsArray($Files) Then
        For $i=1 To $Files[0]
            $FilePath=$Dir&"\"&$Files[$i]
            ReDim $List[UBound($List)+1]
            $List[0]=$List[0]+1
            $List[UBound($List)-1]=$FilePath
        Next
    EndIf
    $SubDir=_FileListToArray($Dir,"*",2)
    If IsArray($SubDir) Then
        For $i=1 To $SubDir[0]
            $FullPath=$Dir&"\"&$SubDir[$i]
            $tempList=FileListToArray($FullPath)
            For $i=1 To $tempList[0]
                ReDim $List[UBound($List)+1]
                $List[0]=$List[0]+1
                $List[UBound($List)-1]=$tempList[$i]
            Next    
        Next
    EndIf
    Return $List
EndFunc
Edited by FlyInSky
Link to comment
Share on other sites

I have another script about it,it's work,why my script don't work?

Func _filelist($searchdir)        
$search = FileFindFirstFile($searchdir & "\*.*")       
If $search = -1 Then return -1              
While 1
    $file = FileFindNextFile($search)               
    If @error Then                 

  FileClose($search)               
  return                                     
 Elseif  $file = "."  or $file = ".." Then       
  ContinueLoop                                              
 ElseIf stringinstr(FileGetAttrib($searchdir & "\" & $file),"D") then       
  _filelist($searchdir & "\" & $file)        

    EndIf                              
ConsoleWrite( $searchdir & "\" & $file & @crlf )
WEnd
EndFunc
Link to comment
Share on other sites

  • 2 months later...

I'm very new to Autoit3. Well, I needed such a function, too,so I made one which works :P

Func _getdirandsubdirs($dir)
$c=1;
$d=0;
$temp="";
$folders=_FileListToArray($dir,"*.",2)
While $c < UBound($folders, 1)
    $temp=_FileListToArray($musicfolder&$folders[$c],"*.",2)
        $d=1;
    While $d < UBound($temp, 1)
        _ArrayAdd($folders,$folders[$c]&"/"&$temp[$d])
        $d=$d+1;
    WEnd
    $c=$c+1;
WEnd
_ArrayDelete($folders, 0)
_ArraySort($folders);
return $folders;
EndFunc
Edited by suppa2
Link to comment
Share on other sites

  • 3 weeks later...

I write a autoit udf to suport subdirectory and suport RegExp, see:

http://www.autoitscript.com/forum/index.php?showtopic=40063

my UDF:myReplaceStringInFile suport StringRegExp and subdirectorymyFileListToArray suport StringRegExp and subdirectorymyImageIdentify get all information from image, use Image Magick com supportautoit in Chinaautoit 论坛yidabu成功社区

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