Organize Files in Subfolders

This process prompts the user to select a folder. It then retrieves all files in that folder and copies them in a subfolder hierarchy based on when they were created. For example, if a file is created in March of 2017, it will be saved in the 20173 subfolder. If the subfolder does not exist it is created automatically.

Display.SelectFolder Description:'Select a folder that contains the files' \
                    InitialDirectory:'' \
                    IsTopMost:False \
                    SelectedFolder=> SelectedFolder \
                    ButtonPressed=> ButtonPressed
#Checks if the user pressed the OK button in the previous dialog). If not (i.e if the user pressed the "Cancel" button), the main body of the Process will not be executed.

if ButtonPressed='OK' then 
    Folder.GetFiles Folder:SelectedFolder  \
                    FileFilter:'*' \
                    IncludeSubfolders:False \
                    FailOnAccessDenied:True \
                    SortBy1:Folder.SortBy.NoSort \
                    SortDescending1:False \
                    SortBy2:Folder.SortBy.NoSort \
                    SortDescending2:False \
                    SortBy3:Folder.SortBy.NoSort \
                    SortDescending3:False \
                    Files=> Files
    loop foreach item in Files
        #The next action creates the subfolder where the current file must be copied. If such a subfolder already exists (probably because it was created in a previous iteration), the next action will do nothing.

        Folder.Create FolderPath:SelectedFolder  \
                    FolderName:item.CreationTime.Year+'\\'+item.CreationTime.Month  \
                    Folder=> DestinationFolder
        #Copies the "item" (the file of the current iteration) in the destination folder. The corresponding destination folder is stored into the variable "DestinationFolder" which has been populated by the previous action.

        File.Copy Files:item  Destination:DestinationFolder  IfFileExists:File.IfExists.DoNothing CopiedFiles=> CopiedFiles
    end
end

Display.ShowMessage Title:'Process Completed!' \
                    Message:'Process "Organize Files in Subfolders" completed.' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed