Jump to content
Sign in to follow this  
nacerbaaziz

How to Find Files in Subfolders

Recommended Posts

nacerbaaziz

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

Share this post


Link to post
Share on other sites
JLogan3o13

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz

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

Share this post


Link to post
Share on other sites
JLogan3o13
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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz

I tried it
I have a problem
I did not know how to use it if there were multiple subfolders
For example a main folder and then a first subfolder with other subfolders inside it

Is there a simple suggestion or example to do this

Share this post


Link to post
Share on other sites
Earthshine

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

 

Share this post


Link to post
Share on other sites
nacerbaaziz

please
Can be more simplistic
Because I did not understand well

I apologize for my foolishness

Share this post


Link to post
Share on other sites
Earthshine

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

 

Share this post


Link to post
Share on other sites
JLogan3o13

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz

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

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  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • TheSaint
      By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I have a question please
      I've searched a lot on how to make a GUI for programs designed by Autoit to accepts dragging files from Windows File Explorer
      Unfortunately, however, it failed
      Is there any way to do this?
      Where I am making a audio player and I want to activate the feature of dragging files from Windows Explorer to a program window to play them
      I hope to find a simple solution here in this wonderful forum
      Thank you very much in advance
    • KimberlyJillPereira
      By KimberlyJillPereira
      Using the alarm received parameter how to search for the picture that matches the year month day hour min and sec and by the name of the .jpg file the jpg file naming format is first letter is always m followed by last two digits of year then two digit month two digit day two digit hour two digit minute and two digit second then get that picture and paste it in Microsoft Excel.How to do it? Please help me. Thank you.



×