Jump to content

How to Find Files in Subfolders


Recommended Posts

hello dears
First I would like to apologize to you for my many questions.
I have a new question if you allow
I am programming an audio player for blinds
I had a problem
I put an option in the folders context menu to Opens the audio files that in the selected folder
I did not know how to make the Autoit Search the subfolders
Please provide an example of how to search for  files in the subfolders
Let's say, for example, MP3 files
Just give me a simple example and I will try to modify it as appropriate for the program I designing it
Please help me to find the solution
Thanks in advance

Link to comment
Share on other sites

  • Moderators

@nacerbaaziz It would help a lot if you would post your code in the future, rather than asking us to guess. If you want to search subfolders, look at _FileListToArrayRec() in the help file.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hello again
Dear I tried to explain what I want in detail
Because I have no idea how to do it
I tried a lot but i did not succeed
I only knew how to search in one folder
But I did not know how to search subfolders that branch out from an original folder
for that  I asked for your help
If you want the code you typed to search in one folder
Here is the code
local $dir = $fileOpen & "\"
$pos = 0

GUICtrlSetData($list, "")
dirAdd($dir)
_GUICtrlListBox_SetCurSel($list, 0)
func dirAdd($dir = $dir)
    _GUICtrlListBox_BeginUpdate($List)
    _GUICtrlListBox_Dir($List, $dir & "\*.mp3")
    _GUICtrlListBox_Dir($List, $dir & "\*.wav")
    _GUICtrlListBox_Dir($List, $dir & "\*.ogg")
    _GUICtrlListBox_Dir($List, $dir & "\*.mp1")
    _GUICtrlListBox_Dir($List, $dir & "\*.mp2")

    _GUICtrlListBox_Dir($List, $dir & "\*.men")

    _GUICtrlListBox_endUpdate($List)
for $i = 0 to _GUICtrlListBox_GetCount($list)-1
$text = _GUICtrlListBox_GetText($list, $i)
    _GUICtrlListBox_ReplaceString($list, $i, $text & ": " & $dir & $text)
next
_GUICtrlListBox_SelectString($list, _GetFileName($file) & ": " & $file)
endFunc

I hope you can help me

Link to comment
Share on other sites

  • Moderators
2 hours ago, nacerbaaziz said:

I hope you can help me

Did you look at _FileListToArrayRec in the help file as now two people have suggested?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

so you tried the code, straight from the help file, and it did not find all the files in subfolders? really? it works for me.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sAutoItDir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1))
    If StringRight($sAutoItDir, 5) = "beta\" Then
        $sAutoItDir = StringTrimRight($sAutoItDir, 5)
    EndIf
    ConsoleWrite($sAutoItDir & @CRLF)

    ; A sorted list of all files and folders in the AutoIt installation
    Local $aArray = _FileListToArrayRec($sAutoItDir, "*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Sorted tree")

    ; And now ignoring the "Include" folder
    $aArray = _FileListToArrayRec($sAutoItDir, "*||include", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "No 'Include' folder")

    ; A sorted list of all but the .exe files in the \AutoIt3 folder
    $aArray = _FileListToArrayRec($sAutoItDir, "*|*.exe", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Non .EXE files")

    ; And here are the .exe files we left out last time
    $aArray = _FileListToArrayRec($sAutoItDir, "*.exe", $FLTAR_FILES)
    _ArrayDisplay($aArray, ".EXE Files")

    ; A test for all folders and .exe files only throughout the folder tree, omitting folders beginning with I (Icons and Include)
    $aArray = _FileListToArrayRec($sAutoItDir, "*.exe||i*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Recur with filter")

    ; Look for icon files - but exlude the "Icons" folder
    $aArray = _FileListToArrayRec($sAutoItDir, "*.ico||ic*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Ooops!", "No ico files found")
    Else
        _ArrayDisplay($aArray, "Icon files not in 'Icons' folder")
    EndIf

    ; And to show that the filter applies to files AND folders when not recursive
    $aArray = _FileListToArrayRec($sAutoItDir, "*.exe", $FLTAR_FILESFOLDERS, $FLTAR_NORECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Non-recur with filter")

    ; The filter also applies to folders when recursively searching for folders
    $aArray = _FileListToArrayRec($sAutoItDir, "Icons", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Folder recur with filter")

    ; Note the exlude_folder parameter is ignored when looking for folders - "Icons" will be excluded but "Include" will still be there
    $aArray = _FileListToArrayRec($sAutoItDir, "*|ic*|i*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "'Icons' out - 'Include' in")

    ; The root of C:\Windows showing hidden/system folders
    $aArray = _FileListToArrayRec("C:\Windows\", "*", $FLTAR_FOLDERS)
    _ArrayDisplay($aArray, "Show hidden folders")

    ; The root of C:\Windows omitting hidden/system folders
    $aArray = _FileListToArrayRec("C:\Windows\", "*", $FLTAR_FOLDERS + $FLTAR_NOHIDDEN + $FLTAR_NOSYSTEM)
    _ArrayDisplay($aArray, "Hide hidden folders")
EndFunc   ;==>Example

 

Capture.PNG

Capture.PNG

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

i posted code you can copy and run. That code is out of the help file and demonstrates all the different ways you can use this function to include or exclude things and to search recursively.

study the code. I can't make you understand it.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $sAutoItDir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1))
    If StringRight($sAutoItDir, 5) = "beta\" Then
        $sAutoItDir = StringTrimRight($sAutoItDir, 5)
    EndIf
    ConsoleWrite($sAutoItDir & @CRLF)
; A sorted list of all files and folders in the AutoIt installation
    Local $aArray = _FileListToArrayRec($sAutoItDir, "*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Sorted tree")
EndFunc

the _ArrayDislplay call displays all the files under all the folders. after you have the array, (you do not need to display it) you can programatically get to each file from that list if you wish. whatever you need to do.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators

@nacerbaaziz people are only going to hold your hand to much around here. You should know by now that expecting people to do everything for you because you "just don't understand" is not going to work. Read the content in the help file and try it for yourself. I guarantee you have not done this yet, as the code in the help file example works just fine.

Come back after you have put in some effort on your own.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hello again
I tried a lot
I found the search method in the first subfolders
But I did not know how to search folders that branch out from subfolders
Is there a way to do this
This is the code that I've tried
#include <Array.au3> ; Only required to display the arrays
#include <MsgBoxConstants.au3>
#include <file.au3>
local $files, $next
local $folder = FileSelectFolder("please select a folder", "")
$files = FileFindFirstFile($folder & "\*.mp3")
while 1
$next = FileFindnextFile($files)
if @error then exitLoop
fileWrite(@scriptDir & "\files.txt", $folder & "\" & $next & @crlf)
WEnd
    Local $aArray = _fileListToArrayRec($folder, "*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
for $i = 1 to $aArray [0]
$files = FileFindFirstFile($folder & "\" & $aArray [$i] & "\*.mp3")
while 1
$next = FileFindnextFile($files)
if @error then exitLoop
fileWrite(@scriptDir & "\files.txt", $folder & "\" & $aArray[$i] & "\" & $next & @crlf)
WEnd
next
exit

Please help me
Thanks in advance

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

×
×
  • Create New...