Sign in to follow this  
Followers 0
BananaFredSoft

Finding files in directories

5 posts in this topic

I have been trying to make a function that finds all of the wav/mp3 files in a directory, even in the subdirectories and then indexes them. Here is my failed attempt:

Func IndexDirectory ()
    $rootdir = FileSelectFolder("Select the directory to index.", "")
    $dir = $rootdir & "\"
    $ff = FileFindFirstFile($dir & "*")
    While 1
        $nd = FileFindNextFile($ff)
        If @error Then
            $dir = getdir($dir)
            If $dir = getdir($rootdir) Then ExitLoop
        ElseIf BitOR(StringRight($nd, 3) = "mp3", StringRight($nd, 3) = "wav") Then
            IndexFile($dir & $nd)
        ElseIf StringInStr(FileGetAttrib($dir & $nd), "D") Then
            $dir = $dir & $nd
            $ff = FileFindFirstFile($dir & "*")
        EndIf
    WEnd
EndFunc

Func IndexFile ($file)
    MsgBox(0, "Debug", $file)
EndFunc

Func getdir($filename)
    $split = StringSplit($filename, "\")
    If Not @error Then
        $dir = ""
        $num = 1
        Do
            $dir &= $split[$num] & "\"
            $num += 1
        Until $num = $split[0]
        Return $dir
    EndIf
EndFunc   ;==>getdir

Can anyone help make this work?

Thanks in advance :)

Share this post


Link to post
Share on other sites



Look in randallc's signature for FileListToArray .... You can also look for _FileListToArrayEx() which I wrote in the examples forum, but I believe Randall's is now faster.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Look in randallc's signature for FileListToArray .... You can also look for _FileListToArrayEx() which I wrote in the examples forum, but I believe Randall's is now faster.

Does it get files in subdirectories?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I still can't figure out how to make a function that utilizes this and gets all of the .mp3/.wavs in subdirectories.

Edited by BananaFredSoft

Share this post


Link to post
Share on other sites

I still can't figure out how to make a function that utilizes this and gets all of the .mp3/.wavs in subdirectories.

Did you bother to look up the 2 functions I told you to find? They both have the option to look for "specific extensions"/with Recurse.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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