File System - Delete

Declaration

<AMFILESYSTEM ACTIVITY="delete" MODE="text (options)" SOURCE="text" TORECYCLE="YES/NO" RESULTDATASET="text" SUBFOLDERS="YES/NO" EXCLUDE="text" RE="YES/NO" ISNEWERTHAN="%DateSerial+TimeSerial%" ISOLDERTHAN="%DateSerial+TimeSerial%" ATTRFILTER="+r-a-s-h+c+e" />

Related Topics    

Description

Deletes the files or folders specified. To specify more than one file/folder, use wildcard characters (for example, * or ?). To specify multiple files or wildcard masks, separate them with a pipe symbol (for example, c:\*.txt|c:\*.bak).

Practical usage

Commonly used for batch removal of redundant or unnecessary folders, files or system directories. You can permanently delete folders/files or send them to the Recycle Bin. You can also retrieve information about the deleted folders/files for reporting purposes.

Parameters

General

Property Type Required Default Markup Description
File/Folder Text (Options) Yes File MODE="folder"

Indicates the type of items to delete. Parameters located in the File options section vary depending on which option is selected. The available options are:

  • File (default) -  This activity will delete one or more files.
  • Folder - This activity will delete one or more folders.

Source

Text

Yes

(Empty)

  • SOURCE="c:\folder\file.txt"
  • SOURCE="c:\folder\*.txt"
  • SOURCE="c:\folder1\|c:\folder2"
  • SOURCE="c:\folder\subfolder"

The path of the folders or files to delete. This can be a fully qualified path and file name (preferred) or a single file (requires use of the File System - Change folder activity). You can use wildcard characters (for example, * or ?) to specify all files matching a certain mask. You can specify multiple files and file masks by separating each entry with a pipe character (|) (for example, c:\temp\*.txt|c:\backup\*.bak). See File Masks & Wildcards for more details.

NOTE: Files with invalid paths are ignored at runtime.
Place in Recycle Bin Yes/No No No TORECYCLE="YES" If selected, folders/files are sent to the Recycle Bin. If disabled (default), folders/files are deleted permanently.
Create and populate dataset with results Text No (Empty) RESULTDATASET="DatasetName" The name of a dataset to create and populate with information pertaining to results of this operation. More about the individual dataset fields that this activity creates can be found below under Datasets.

File Options

Property Type Required Default Markup Description
Include subfolders Yes/No No No SUBFOLDERS="YES" If selected, denotes that, if present, subfolders should be searched for files matching the mask specified in the Source parameter. If disabled (default), subfolders are ignored.
Exclude mask Text No (Empty)
  • EXCLUDE="*.txt"
  • EXCLUDE="*.txt|*.bak"
  • EXCLUDE="c:\foldename"
Causes this activity to omit deleting folders/files matching the masks specified. Wildcard masks (for example, * or ?) may be used. Multiple entries may be specified by separating them with a pipe symbol (|) (for example, *.txt|*.bak).
Regular expression Yes/No No No RE="yes" If selected, indicates that any value entered in the Exclude mask parameter will be interpreted as a regular expression. If disabled (default) the value will be interpreted as normal readable text.
Only if newer than Date No (Empty) ISNEWERTHAN="%DateSerial(2001,10,12) + TimeSerial(00,00,00)%" If enabled, causes this action to only act on folders/files that are newer than the date/time specified. If this parameter is left blank or disabled (default), folder/file dates are ignored. Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression.
Only if older than Date No (Empty) ISOLDERTHAN="%DateSerial(2001,10,12) + TimeSerial(00,00,00)%" If enabled, causes this action to only act on folders/files that are older than the date/time specified. If this parameter is left blank or disabled (default), folders/file dates are ignored. Click the Custom button to select from a list of pre-defined date parameters. Enable the Expression option to allow entry of a date/time expression.

File Filter

Property Type Required Default Markup Description
Attributes Text (options) No Doesn't matter ATTRFILTER="+R+A-H" (compress read-only & archive files but not hidden files) Instructs the activity to filter which files to act on, based on whether the file's original attribute settings match the attribute settings specified in this parameter. In Task Builder's visual mode, drop-down boxes are provided within the activity's settings to assist in the selection of attribute settings. In Task Builder's AML mode, a text item must be entered that contains the original attribute mask of the files you wish to affect. For example, if Read-only attribute is set to Off (in visual mode) or -R (in AML mode) , only source files with the Read-only attribute turned off are affected. Source files with Read-only attribute turned on will be ignored. The available options are:
  • Read-only attribute is - Specifying On or +R includes files with this attribute turned on. Specifying Off or -R includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.
  • Archive attribute is - Specifying On or +A includes files with this attribute turned on. Specifying Off or -A includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.
  • System attribute is - Specifying On or +S includes files with this attribute turned on. Specifying Off or -S includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.
  • Hidden attribute is- Specifying On or +H includes files with this attribute turned on. Specifying Off or -H includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.
  • Compression attribute is - Specifying On or +C includes files with this attribute turned on. Specifying Off or -C includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.
  • Encrypted attribute is - Specifying On or +E includes files with this attribute turned on. Specifying Off or -E includes files with this attribute turned off. Specifying Doesn't matter (default) or excluding the letter ignores this attribute.

Description

Error Causes

On Error

Additional notes

Datasets

A dataset is a multiple column, multiple row container object. This activity creates and populates a dataset containing a specific set of fields. The table below describes these fields (assuming the dataset name assigned was "theDataset").

Name Type Return Value
theDataset.Source Text The path and file name of the source folder/ file.
theDataset.Size Number The size of the folder/file (in kb).
theDataset.Destination Text The path and file name of the destination file.
theDataset.Result True/False Returns TRUE if result of activity is a success, otherwise, returns a FALSE.
theDataset.Message Text The textual information associated to the result.

Examples

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Example 1

This sample task deleted all files in "c:\folder1" to the recycle bin and creates and populate a dataset named "theDataset" with details of the files. A Loop Dataset action is then used to loop through the files that were deleted. Within each loop process, details about each deleted file (for example, source location, result) is displayed in a message box.

Copy
<AMFILESYSTEM ACTIVITY="delete" SOURCE="c:\folder1\*.*" TORECYCLE="YES" RESULTDATASET="the Dataset" />
<AMLOOP ACTIVITY="dataset" DATASET="the Dataset" />
<AMSHOWDIALOG WINDOWTITLE="Results of the delete operation.">The path and file name of the source file - %theDataset.Source%The result of this operation - 0 for success - %theDataset.Result%The textual information associated to the result - %theDataset.Message%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />

Example 2

This sample one line task that deletes all text files in a specified directory, including files found in any sub-directories.

Copy
<AMFILESYSTEM ACTIVITY="delete" SOURCE="c:\folder1\*.*" RESULTDATASET="the Dataset" SUBFOLDERS="YES" />