Jump to content
Sign in to follow this  
FlyInSky

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

Recommended Posts

FlyInSky

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

Share this post


Link to post
Share on other sites
FlyInSky

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

Share this post


Link to post
Share on other sites
suppa2

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

Share this post


Link to post
Share on other sites
yidabu

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成功社区

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.