DeleteFile -- delete a file or directory
DeleteFile(file$[, callback, userdata, pattern$, matchdir])
Deletes the specified file or directory. This function does not fail if the specified file or directory does not exist. Please note that this function will delete whole directories, too. It does not check if the specified directory is empty or not! If you specify a directory, it will be deleted with all subdirectories and all files in it. So be very careful with this function!

Starting with Hollywood 5.0, you can pass a filter pattern in the optional argument pattern$. In that case, DeleteFile() will only delete the files that match the specified pattern. For example, passing *.jpg in pattern$ will only delete files that use the .jpg file extension. Of course, using a filter pattern makes only sense if you pass a directory in file$. The optional argument matchdir specifies whether or not the filter pattern should also be matched against subdirectories. If this is set to True, DeleteFile() will only recurse into subdirectories that match the specified filter pattern. If it is set to False, DeleteFile() will recurse into all subdirectories. For compatibility reasons, matchdir defaults to True, but most of the time you will want to pass False here because it usually does not make sense to match the file pattern against a directory name. For example, it does not make sense to match the *.jpg example from above against directories, too. The pattern specified in pattern$ must adhere to the pattern rules as described in the documentation of the MatchPattern() function. See MatchPattern for details.

For fine-tuned control of the delete operation, you can specify a callback function in argument 2. DeleteFile() will call it from time to time so that you could update a progress bar for example. Additionally, if you specify a callback function, DeleteFile() will ask you to confirm the unprotection of delete protected files. If there is no callback function, DeleteFile() will silently skip delete protected files. The callback function receives one argument: A table that contains more information. The following callbacks are available:

Callback function type #DELETEFILE_UNPROTECT:


Contains the delete protected file that is to be unprotected. (fully qualified path)

Contains the value you specified in the userdata argument.

The callback function of type #DELETEFILE_UNPROTECT will be called if the file that should be deleted is delete protected. This callback function needs to return True, if it is okay to unprotect the file or False if it shall not be unprotected. If you return -1, the delete operation will be completely aborted.

Callback function type #DELETEFILE_STATUS:


Contains the fully qualified path of the file that is to be deleted next

Contains the value you specified in the userdata argument.

The callback function of type #DELETEFILE_STATUS should normally return False. If it returns True, the delete operation will be aborted.

Starting with Hollywood 3.1 there is an optional argument called userdata. The value you specify here is passed to your callback function whenever it is called. This is useful if you want to avoid working with global variables. Using the userdata argument you can easily pass data to your callback function. You can specify a value of any type in userdata. Numbers, strings, tables, and even functions can be passed as user data.

Filename or directory to delete
optional: a callback function to use (V2.0)
optional: user specific data to pass to callback function (V3.1)
optional: filter pattern to use for determining which files to delete (V5.0)
optional: whether or not to apply the filter pattern to directories also (defaults to True) (V5.0)
Deletes the file "FooBar" from the current directory.

Function p_DeleteCallback(msg)
  Switch msg.action
    DebugPrint("Now deleting", FilePart(msg.file))
    Return(SystemRequest("Hollywood", FilePart(msg.file) ..
      " is delete protected!\nDo you want me to unprotect it?",
DeleteFile("TestDir", p_DeleteCallback)
Demonstrates the usage of a callback function. It will delete the directory "TestDir" from the current directory and print out information about the file that is currently being deleted.

Show TOC