fileDelete

Deletes the specified file on the server. fileDelete throws an exception whenever a file doesn't exist.

fileDelete(file) → returns void

fileDelete Argument Reference

filepath
Required

Pathname of the file to delete. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.

Examples sample code invoking the fileDelete function

Obtaining files within an archive folder and then removing them if they are older than one hour.

var existingFiles = directoryList(expandPath("/archive/"), false, "query");
for (file in existingFiles) {
	if (dateDiff("h", file.datelastmodified, now()) GT 1) {
		fileDelete(file.directory & "\" & file.name);
	}
}

Expected Result: All files within the archive directory older than one hour will be deleted.


Fork me on GitHub