Delete from Directory

Verb: deleteFromDirectory

Deletes files from a directory and its subdirectories, and may also delete the subdirectories themselves.

Syntax

deleteFromDirectory --directory(String) [--usepattern(Boolean)] --filemask(String) [--deletesubfiles(Boolean)] [--deletesubfolders(Boolean)] [--fileSystem(FileSystem)]

Inputs

Script Designer Required AcceptedTypes Description
--directory Directory Path Required Text Directory path from which the content should be deleted.
--usepattern Use Mask Optional Boolean When enabled, it allows the use of a mask to filter the contents that should be deleted.
--filemask Mask Only whenUse Mask is True Text Filter that will be applied in the search. It must be inserted as follows: [Name or part of the file name, spaces are not accepted in this part]. [File extension]. Here are some examples:
  • * .txt: filters all files with the ".txt" extension;
  • name: filters all files that have the word "name" as part of the name.

  • When entering the name of the file, it must be case sensitive.
    --deletesubfiles Delete subdirectory file Optional Boolean When enabled, files in the subdirectories are deleted.
    --deletesubfolders Deleted Subfolders Optional Boolean When enabled, subdirectories are deleted.
    --fileSystem File System Optional File System File system connection variable.
    1. To obtain the connection variable with an available file system, this connection must be established using one of the following commands: IBM RPA Control Center.
    2. If nothing is specified in this parameter, the operating system's local file system is used by default.

    Example

    Example 1: The Delete from Directory command, with the Delete subdirectory file and Deleted Subfolders parameters enabled, deletes all existing files and directories within the "IBMDirectory" directory, which was created before using the Create Directory command inside the loop For.

    defVar --name documentsPath --type String
    defVar --name filesDirectory --type String
    defVar --name directoryExists --type Boolean
    defVar --name counter --type Numeric
    defVar --name subDirectoryPath --type String
    getSpecialFolder --folder "MyDocuments" documentsPath=value
    // Create a structure of directories and subdirectories to be deleted.
    goSub --label deleteDirectory
    createDir --path "${documentsPath}\\IBMDirectory" filesDirectory=value
    for --variable ${counter} --from 0 --to 4 --step 1
    	writeToFile --value "This is the file number: ${counter}" --file "${filesDirectory}\\file${counter}.txt"
    	createDir --path "${filesDirectory}\\Directory_${counter}" subDirectoryPath=value
    	writeToFile --value "Subdirectory Content" --file "${subDirectoryPath}\\subdirectory_content.txt"
    next
    // Delete all files and subdirectories in the directory named "IBMDirectory".
    deleteFromDirectory --directory "${filesDirectory}" --deletesubfiles  --deletesubfolders
    beginSub --name deleteDirectory
    	ifFolder --path "${filesDirectory}\\IBMDirectory" directoryExists=value
    	if --left "${directoryExists}" --operator "Is_True"
    		deleteDir --directoryname "${documentsPath}\\IBMDirectory"
    	endIf
    endSub
    

    Example 2: The Delete from Directory command, with the Delete subdirectory file and Deleted Subfolders parameters enabled and with a "file" filter mask, deletes all files and subdirectories that have the word "file" within the "IBMDirectory" directory, which was created earlier through the Create Directory command within the loop For.

    defVar --name documentsPath --type String
    defVar --name filesDirectory --type String
    defVar --name directoryExists --type Boolean
    defVar --name counter --type Numeric
    defVar --name subdirectoryPath --type String
    getSpecialFolder --folder "MyDocuments" documentsPath=value
    // Create a structure of directories and subdirectories to be deleted.
    goSub --label deleteDirectory
    createDir --path "${documentsPath}\\IBMDirectory" filesDirectory=value
    for --variable ${counter} --from 0 --to 4 --step 1
    	writeToFile --value "This is the file number: ${counter}" --file "${filesDirectory}\\file${counter}.txt"
    	createDir --path "${filesDirectory}\\Directory_${counter}" subdirectoryPath=value
    	writeToFile --value "Subdirectory Content" --file "${subdirectoryPath}\\Subdirectory_Content.txt"
    next
    // Delete all files and subdirectories that have the word "file" in their name from the directory named "IBMDirectory".
    deleteFromDirectory --directory "${filesDirectory}" --usepattern  --filemask arquivo --deletesubfiles  --deletesubfolders
    beginSub --name deleteDirectory
    	ifFolder --path "${documentsPath}\\IBMDirectory" directoryExists=value
    	if --left "${directoryExists}" --operator "Is_True"
    		deleteDir --directoryname "${documentsPath}\\IBMDirectory"
    	endIf
    endSub
    

    See Also

  • Check If Directory Exists
  • Convert Base64 to File
  • Convert File to Base64
  • Copy File
  • Count Files
  • Create Directory
  • Delete Directory
  • Delete File
  • Download from File System
  • Get Directories
  • Get Files
  • If File Exists
  • Move File
  • Read All Bytes
  • Read All Text
  • Rename File
  • Send to File System
  • Write to File