Copy File

This process will prompt the user to select a file and a destination folder. It will then copy the selected file into the destination folder.

Display.SelectFile Title:'Please select the file to copy' \ 
                    InitialDirectory:'' \
                    FileFilter:'' \ 
                    IsTopMost:False \
                    CheckIfFileExists: True \
                    SelectedFile=> SelectedFile \
                    ButtonPressed=> ButtonPressedinFileDialog

Display.SelectFolder Description:'Select the destination directory' \
                    InitialDirectory:'' \
                    IsTopMost:False \
                    SelectedFolder=> DestinationDirectory \
                    ButtonPressed=> ButtonPressedInFolderDialog

if ButtonPressedInFileDialog = 'Open' and ButtonPressedInFolderDialog = 'OK' then
                File.Copy Files:FileToCopy \ 
                    Destination:DestinationDirectory \ 
                    IfFileExists:File.IfExists.DoNothing \ 
                    CopiedFiles=> CopiedFiles
end

Display.ShowMessage Title:'Example Completed!' \
                    Message:'“Copy File” completed' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed

In more detail:


The process will check whether the user has selected both paths. If so, it will copy the file into the specified folder. Otherwise, the process will be completed without having copied any file. In any case, a message will be displayed to inform the user that the process is completed.

Step 1: Select a File and a Folder

Prompt the user to select a file to be copied, as well as the destination folder.

Display.SelectFile Title:'Please select the file to copy' \
                    InitialDirectory:'' \ 
                    FileFilter:'' \ 
                    IsTopMost:False \ 
                    CheckIfFileExists:True \ 
                    SelectedFile=> SelectedFile \ 
                    ButtonPressed=> ButtonPressedinFileDialog

Display.SelectFolder Description:'Select the destination directory' \
                    InitialDirectory:'' \
                    IsTopMost:False \
                    SelectedFolder=> DestinationDirectory \
                    ButtonPressed=> ButtonPressedInFolderDialog
  1. Use the “Display.SelectFile” action. This action displays the “Select File” dialog and prompts the user to select a file.
    1. Set the “Title” argument to “Please select the file to copy”. Otherwise, the default title will be displayed, which is “Open”.
    2. Set the “CheckIfFileExists” argument to “True”. This arrangement informs the user if the file was not found and prompts them to check the filename and try again. Otherwise, the process will error out.
    3. Change the output variables’ names: from “SelectedFile” to “FileToCopy”and from“ButtonPressed” to “ButtonPressedInFileDialog”

  2. Use the “Display.SelectFolder” action. This action displays the “Select Folder” dialog and prompts the user to select a folder.
    1. Set the “Description” title to “Select the destination directory”.
    2. Rename the output variable “SelectedFolder” to “DestinationDirectory”
    3. Rename the output variable“ButtonPressed” to “ButtonPressedInFolderDialog”

Step 2: Copy the File into the Folder

Check whether the user selected a file, by checking the value of the “ButtonPressedInFileDialog” attribute of the previous action . If a file was selected, the attribute will hold the value “Open”. Additionally, check whether the user selected a destination folder, by checking whether the “ButtonPressedInFolderDialog” holds the value“OK”. If a file and a folder have been selected, copy the file into that folder. Otherwise, the process will be completed without having copied any folder.

if ButtonPressedInFileDialog = 'Open' and ButtonPressedInFolderDialog = 'OK' then
                File.Copy Files:FileToCopy \
                            Destination:DestinationDirectory \
                            IfFileExists:File.IfExists.DoNothing \
                            CopiedFiles=> CopiedFiles
end
  1. Use the “if” statement to check whether the user pressed the “Open” button in the “Select File” dialog and the “Ok” button in the “Select Folder” dialog.
  2. Use the “File.Copy” action
    1. Set the “Files” argument to “FileToCopy”, which is an output variable of the “Display.SelectFile” action (used in the first step).
    2. Set the “Destination” argument to “DestinationDirectory”, which is an output variable of the “Display.SelectFolder action”.
  3. Close the conditional block, using the “end” statement.

Step 3: Display a message when the process is completed

Inform the user when the process is completed.

Display.ShowMessage Title:'Process Completed!' \
                    Message:'“Copy File” completed' \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed

Use the “Display.ShowMessage” action

  1. Set the “title” argument to “Process Completed!”.
  2. Set the “Message” argument to “‘Copy File’ completed”.