File System - Delete

Declaration

<AMFILESYSTEM ACTIVITY="delete" SUBFOLDERS="yes/no" EXCLUDE="text" RE="yes/no" MODE="text (options)" SOURCE="text" TORECYCLE="yes/no" RESULTDATASET="text" />

Description:

Deletes the file(s) or folder(s) specified. To specify more than one file/folder, use wildcard characters (e.g.,* or ?). To specify multiple files or wildcard masks, separate them with a pipe symbol (e.g.,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 item(s) 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)

  1. SOURCE="c:\sourcefolder\file.txt"

  2. SOURCE="c:\sourcefolder\*.txt"

  3. SOURCE="c:\folder\*.txt|c:\folder\*.bak"

  4. SOURCE="c:\foldername\subfoldername

The path of the folder(s) or file(s) to delete. This can be a fully qualified path and folder/file name (preferred) or a folder/file name only (requires use of the Change Folder action). Wildcard characters (e.g.,* or ?) may be used to delete folders/files matching a certain mask. Multiple files and file masks may be specified by separating each entry with a pipe symbol (e.g.,c:\*.txt|c:\*.bak).

Place in Recycle Bin

Yes/No

No

No

TORECYCLE="YES"

If set to YES, folders/files are sent to the Recycle Bin. If set to NO (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 set to YES, denotes that, if present, subfolders should be searched for files matching the mask specified in the Source parameter. If set to NO (default), subfolders are ignored.

Exclude mask

Text

No

(Empty)

  1. EXCLUDE="*.txt"

  2. EXCLUDE="*.txt|*.bak

  3. EXCLUDE="c:\foldename"

Causes this activity to omit deleting folders/files matching the mask(s) specified.Wildcard masks (e.g.,* or ?) may be used. Multiple entries may be specified by separating them with a pipe symbol (|). Example: *.txt|*.bak

Regular expression

Yes/No

No

No

RE="yes"

If set to YES, indicates that any value entered in the Exclude mask parameter will be interpreted as a regular expression. If set to NO (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

(Empty)

ATTRFILTER="+R+A-H" (compress read-only & archive files but not hidden files)

This group of settings causes the activity to filter which files are to be deleted based on the attribute settings of the source file(s). In visual mode, a group of controls are provided to assist in the selection. In markup mode, a single text item must be specified that contains the attributes of the file(s) you wish to delete. Available Options:

  • R—Read-only: Specifying "+R" causes files with this attribute turned on to be included, "-R" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • A—Archive: Specifying "+A" causes files with this attribute turned on to be included, "-A" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • S—System: Specifying "+S" causes files with this attribute turned on to be included, "-S" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • H—Hidden: Specifying "+R" causes files with this attribute turned on to be included, "-H" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

  • C—Compression: Specifying "+C" causes files with this attribute turned on to be included, "-C" causes files with this attribute turned off to be included, not specifying the letter (default) causes this attribute to be ignored.

Description

Error Causes

On Error

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.

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

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 file(s). A Loop Dataset action is then used to loop through the files that were deleted. Within each loop process, details about each deleted file (e.g.,source location, result) is displayed in a message box.

 

<AMFILEDELETE SOURCE="c:\folder1\*.*" TORECYCLE="YES" RESULTDATASET="theDataset" />

<AMLOOP TYPE="DATASET" DATASET="theDataset">

     <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>

 

Example 2 - One line task that deletes all text files in a specified directory, including files found in any sub-directories.

 

<AMFILEDELETE SOURCE="c:\folder1\*.*" SUBFOLDERS="YES" />