Delete All Text Files in a Folder Hierarchy

This process prompts the user to select a folder and then deletes all the text files within that folder and its subfolders.

#Prompts the user to select the folder whose text files will be deleted and stores the folder selected in the "RootFolder" variable.

Display.SelectFolder Description:'Please select the root folder that contains the text files to delete. Press Cancel to exit.' \
                    InitialDirectory:'' \
                    IsTopMost:False \
                    SelectedFolder=> RootFolder \
                    ButtonPressed=> ButtonPressed

#Checks if the user pressed the OK button. If not (i.e if the user pressed the "Cancel" button), the main body of the job will not be executed.

if ButtonPressed='OK' then
#The next action retrieves all files in the selected folder (RoorFolder) and its subfolder that have a .txt extension and saves them as a list of files in the variable "TextFiles"

    Folder.GetFiles Folder:RootFolder  \
                    FileFilter:'*.txt' \
                    IncludeSubfolders:True \
                    FailOnAccessDenied:True \
                    SortBy1:Folder.SortBy.NoSort \
                    SortDescending1:False \
                    SortBy2:Folder.SortBy.NoSort \
                    SortDescending2:False \
                    SortBy3:Folder.SortBy.NoSort \
                    SortDescending3:False \
                    Files=> TextFiles

#The next action will delete the retrieved files.

    File.Delete Files: TextFiles

Display.ShowMessage Title:'Process Completed!' \
Message:'Process "Delete All Text Files in a Folder Hierarchy" completed.' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed