Skip to content

Description

The sample consists of a task that can be copied and pasted into your project. Files can be deleted by the following criteria.

  • Delete oldest file
  • Delete all files older than a certain date and time
  • Delete oldest file until a certain amount of files are left
  • Delete oldest file until a certain amount of space is free

Important Note: When using the parameter "Pattern" in combination with maximum files or minimum space, the task will only delete files that match the pattern but will use the total number of files or space as a reference. For example, if the pattern is set to ".csv" files and the maximum number of files is set to 10. The directory contain 8 files that match the pattern but 15 files in total. The task will delete 5 files that match the pattern to get the total number of files down to 10.

Command structure

The task uses a variable structure to communicate with the outside world that can also be used to interact with other tasks. The structure CleanUp looks as follows:

Level 1 Level 2 Level Description
CMD Used to trigger a command
DeleteMaxFiles Delete oldest file until a certain amount of files are left.
DeleteMinSpace Delete oldest file until a certain amount of space is free.
DeleteOldest Delete oldest file.
DeleteOlderThan Delete all files older than a certain date and time.
UpdateFreeSpace Update free space information. (CleanUp.DAT.FreeSpace)
ErrorReset Reset error.
PAR Parameter structure
Simulate Files are only listed but not actually deleted. The default value is true to protect the user from accidently deleting files.
Device Device name.
Path Path to files.
MaxFilesToKeep Maximum number of files to keep. (Command DeleteMaxFiles)
MinSpace Delete files until minimum space is available. (Command DeleteMinSpace)
OlderThan Delete all files older than this date. (Command DeleteOlderThan)
Pattern File must match this pattern (ex. .pdf or .csv).
DAT Return data from command.
FilesList List of files that were deleted. Only the first x deleted files are listed here.
FilesDeleted Number of files that were deleted.
FilesCount Number of files left in the directory.
FreeSpace Free space on the media.
ERR Information about errors.
State State where the error occurred.
Text Error text.
Status Shows the status as number

Pre-Configuration

The following constants can be adjusted if necessary.

Constant Default Text
FILE_NAME_LEN 200 Maximum file name length.

Error handling

The task generates the following list of error messages. All other error numbers are generated from included libraries that can be found in the Automation Studio help.

No Constant Text
10000 CLEANUP_ERR_FILE_NAME_TO_LONG File name + path exceeds maximum file name length
10001 CLEANUP_ERR_PAR_IS_EMPTY Corresponding parameter for command is empty
10002 CLEANUP_ERR_MIN_SPACE Minimum space could not be achieved
10003 CLEANUP_ERR_MIN_FILES Minimum number of files could not be achieved