DeleteDirectory

Top  Previous  Next

 

The DeleteDirectory command allows you to Delete a specified directory and all of its contents.

lamp Note: If the directory does not exist on your computer unless you use the DeleteDirectoryIfExists DeleteDirectoryOption the command will consider that to be an error and processing of the script will not continue. If you need to use one of the other DeleteDirectoryOptions and want to be sure whether or not the directory already exists you can use a Conditional command along with a Validation Command to perform the check before attempting deletion.

Command Syntax

 

DeleteDirectory:[TargetDirectory],[DeleteDirectoryOption]

 

The colon after the command is compulsory. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, but parameters may be depending on the operating system and locale.

 

Parameters:

 

TargetDirectory: The fully qualified path identifying the directory to delete

DeleteDirectoryOption: A string representing a valid member of the DeleteDirectoryOptions enumeration. Valid values are:  

 

None: Deletes the Directory and its contents. This is the default if no Delete Directory Option is specified.

DeleteDirectoryAndContents: Deletes the directory and its contents. This is the same functionality as specifying the None option

DeleteDirectoryContent: Deletes all files and folders in the specified directory but leaves the directory in place

DeleteDirectoryIfEmpty: Only deletes the directory if it is empty

DeleteDirectoryIfExists: Only deletes the directory if it exists, otherwise the action is ignored

 

The TargetDirectory parameter is compulsory. If the parameter is missing or invalid an error will be thrown. The parameter must be surrounded by quotation marks if one or more spaces are included in the path. It is good practice to include the quotation marks in any case, so that it reduces the risk of error when writing scripts. The DeleteDirectoryOption parameter is optional. The comma is only required if you are specifying a DeleteDirectoryOption.

 

Examples:

 

Delete a directory and its contents:

 

DeleteDirectory:"C:\Test"

 

Delete a directory contents but leave the directory in place:

 

DeleteDirectory:"C:\Test",DeleteDirectoryContent

 

Delete a directory ONLY if it has no contents:

 

DeleteDirectory:"C:\Test",DeleteDirectoryIfEmpty

 

Delete a directory ONLY if it exists:

 

DeleteDirectory:"C:\Test",DeleteDirectoryIfExists

 

See Also: ClearDirectory CreateDirectory MoveDirectory RenameDirectory