Jump to content

List all folders


rst
 Share

Recommended Posts

Just adding two lines... I wrote what ones, if it does not work, you know where look... :)

Func _FolderSearch($sIstr, $bSF)
; $bSF = 1 means looking in subfolders
; $sSF = 0 means looking only in the current folder.
; An array is returned with the full path of all files found. The pos [0] keeps the number of elements.
  Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]
  $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
  If $sCP = '' Then $sCP = @WorkingDir & '\'
  $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
  If $sCriteria = '' Then $sCriteria = '*.*'
  
;To begin we seek in the starting path.
  $sCS = FileFindFirstFile($sCP & $sCriteria)
  While $sCS <> - 1
     $sCF = FileFindNextFile($sCS)
     If @error Then
        FileClose($sCS)
        ExitLoop
     EndIf
     If $sCF = '.' Or $sCF = '..' Then ContinueLoop
     If Not StringInStr($sCP & $sCF,FileGetAttrib($sCP & $sCF),'d') Then ContinueLoop ;;ADDED LINE
     $sOutPut = $sOutPut & $sCP & $sCF & @LF
  Wend
  
;And after, if needed, in the rest of the folders.
  If $bSF = 1 Then
     $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *.
     Do 
        $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1),1);current search.
        $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path.
        $iH = FileFindFirstFile($sCS)
        While $iH <> - 1
           $sCF = FileFindNextFile($iH)
           If @error Then
              FileClose($iH)
              ExitLoop
           EndIf
           If $sCF = '.' Or $sCF = '..' Then ContinueLoop
           If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then
              $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer
              $sFP = $sCP & $sCF & '\';                            for future searches
              $iH2 = FileFindFirstFile($sFP & $sCriteria);         and checked with the criteria.
              While $iH2 <> - 1
                 $sCF2 = FileFindNextFile($iH2)
                 If @error Then
                    FileClose($iH2)
                    ExitLoop
                 EndIf
                 If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop
     If Not StringInStr($sFP & $sCF2,FileGetAttrib($sFP & $sCF2),'d') Then ContinueLoop;;ADDED LINE
                 $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output.
              Wend
           EndIf
        Wend
        $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '')
     Until $sBuffer = ''
  EndIf
  
  If $sOutPut = '' Then
     $aNull[0] = 0
     Return $aNull
  Else
     Return StringSplit(StringTrimRight($sOutPut, 1), @LF)
  EndIf
EndFunc ;==>_FileSearch
Link to comment
Share on other sites

A way I decided to find directories was right out of the help file. So long as there are no files in the folder containing the other directories (or files with the same name you can use what I found in the help file).

Here is what the help file has...

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

If you run that really quickly you will notice that it shows the folders to. So long as you arent wanting to go into sub directories that will work. If you want sub directories... use Larry's or ezzetabi's.

The above is much less code if you just want the directories.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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