Jump to content

Just a Big Thanks


Recommended Posts

I must say thanks to the AutoIt Community for helping me grow as a scripter. I just successfully coded using recursion, something I have never tried before and didn't think I would be able to do. I was surprised to find out that I was able to do it, and that showed me how far I have come in coding since I started. And, that is all credited to the AutoIt Community that has been so patient in teaching me. A big Thanks!

If you want to see the code I worked on, it is below. It lists all the sub-directories and files from a given folder. If anyone thinks it is useful, let me know and I will include it in the Example Scripts. Also, if you think I should modify and submit it for inclusion, then please give me feedback and I will. Thanks again.

#Include <File.au3>
#Include <Array.au3>
$sPath = @MyDocumentsDir & "\Personal\"
Global $iCountFolders=0, $iCountFiles =0
$aNumFolders = GetFolders($sPath)
PrintFolderNames($aNumFolders, $sPath)

Func GetFolders($sPath) ;Takes Path, Return number of Folders and Folder Paths
    Local $aFolderList
    $aFolderList=_FileListToArray($sPath, "*", 2) ;List Only Folders in the given path
    Return $aFolderList ;Number of Folders
EndFunc

Func PrintFolderNames($aNumFolders, $sPath) ;Takes Array, Prints Folder's Path from Array
    Local $sSubFolder, $iCC, $xCC, $aFilesList
    ConsoleWrite ($iCountFolders & @TAB & "Path: " & $sPath & @CRLF) ;Give Path Of Folder
    ;;;;;;;;;;;;;;;;;;;;;;Execute For Files;;;;;;;;;;;;;;;;;;;;;;;;
        ;Give Path of All Files in that Folder
        $aFileList=_FileListToArray($sPath, "*", 1) ;List Only Files in the given path
        If IsArray($aFileList) Then ;Use IsArray To detect if there were any Files in that new Sub Folder, if so, then continue
            For $xCC=1 To $aFileList[0]
                ;If you wanted to Execute something for a File, here is when to do it
                $iCountFiles+=1 ;Keep a count of Number of Files
                $sFilePath = $sPath & $aFileList[$xCC] ;Just give Full Path of File Name
                ConsoleWrite (@TAB & $iCountFiles & @TAB & "File: " & $sFilePath & @CRLF) ;Just Print Full Path of File Name
            Next
        EndIf
    ;;;;;;;;;;;;;;;;;;;;;;End Execute;;;;;;;;;;;;;;;;;;;;;;;;
    
    For $iCC=1 To $aNumFolders[0] ;Start at 1, since the [0] Element is the Ubound
        $iCountFolders+=1 ;Keep a count of Number of Folders
        $sSubFolder = $sPath & $aNumFolders[$iCC] & "\" ;Declare Path for Subfolders
        
        ;;;;;;;;;;;;;;;;;;;;;;Execute For Folder;;;;;;;;;;;;;;;;;;;;;;;;
        ;If you wanted to Execute something for a Folder, here is when to do it
        ;Like Get the Sub Folders

        ;Get All Sub Folders
        $aNumFoldersSubs = GetFolders($sSubFolder) ;Get Folder list in New SubFolder
        If IsArray($aNumFoldersSubs) Then ;Use IsArray To detect if there were any Folders in that new Sub Folder, if so, then continue
            PrintFolderNames($aNumFoldersSubs, $sSubFolder) ;Call Self with new parameters
        EndIf
        ;;;;;;;;;;;;;;;;;;;;;;End Execute;;;;;;;;;;;;;;;;;;;;;;;;
    Next
EndFunc
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...