The FILE_DELETE procedure deletes a file or empty directory, if the process has the necessary permissions to remove the file as defined by the current operating system. FILE_CHMOD can be used to change file protection settings.
Note: On UNIX, if a file to be deleted is a symbolic link, FILE_DELETE deletes the link itself, and not the file that the link points to.
Note: The FILE_DELETE procedure will not ask for confirmation before deleting files. If you are writing an application, you may want to use the DIALOG_MESSAGE function to confirm file deletion.
Examples
In this example, we remove an empty directory named moose:
FILE_DELETE, 'moose'
Syntax
FILE_DELETE, File1[,... Filen] [, /ALLOW_NONEXISTENT] [, /NOEXPAND_PATH] [, /QUIET] [, /RECURSIVE] [, /RECYCLE] [, /VERBOSE]
Arguments
Filei
A scalar or array of file or directory names to be deleted, one name per string element. Directories must be specified in the native syntax for the current operating system.
Note: On Unix, if you use a wildcard "*" character, IDL will find the first file that matches the pattern. Only one file will be deleted, not all files that match. To delete multiple files, FILE_SEARCH to find the list of files.
Keywords
ALLOW_NONEXISTENT
If set, FILE_DELETE will quietly ignore attempts to delete a non-existent file. Other errors will still be reported. The QUIET keyword can be used instead to suppress all errors.
Note: On Unix, if you use a wildcard "*" character to match a file, and that pattern does not match any file name, then IDL will throw an error even if ALLOW_NONEXISTENT is set. In this case you should also set the QUIET keyword to suppress these errors.
NOEXPAND_PATH
Set this keyword to cause FILE_DELETE to use the File argument exactly as specified, without applying the usual file path expansion.
QUIET
FILE_DELETE will normally issue an error if it is unable to remove a requested file or directory. If QUIET is set, no error is issued and FILE_DELETE moves on to the next requested item.
RECURSIVE
By default, FILE_DELETE will refuse to delete directories that are not empty. If RECURSIVE is set, FILE_DELETE will instead quietly delete all files contained within that directory and any subdirectories below it, and then remove the directory itself.
Note: Recursive delete is a very powerful and useful operation. However, it is a relatively dangerous command with the ability to rapidly destroy a great deal of data. Once deleted, files cannot be recovered unless you have a separate backup, so a mistaken recursive delete can be very damaging. Be very careful to specify correct arguments to FILE_DELETE when using the RECURSIVE keyword.
RECYCLE
By default, FILE_DELETE will permanently delete files. If the RECYCLE keyword is set, then FILE_DELETE will move files to the operating system's recycle (or trash) bin, so that the files can be recovered.
Note: This keyword is only available on Windows platforms. On other platforms this keyword will be quietly ignored and the files will be permanently deleted.
VERBOSE
The VERBOSE keyword causes FILE_DELETE to issue an informative message for every file it deletes.
Version History
5.4 |
Introduced |
5.6 |
Added ALLOW_NONEXISTANT and VERBOSE keywords
|
8.4 |
Added RECYCLE keyword |
See Also