remove()
Remove a file from the file system.
Syntax
remove(filename)
Parameter
Parameter | Definition |
---|---|
filename | name and path of the file to be removed from the file system |
Description
The remove() function:
- removes a specified file, filename, from the file system The full path of the file must be included in the filenameparameter.
- returns 1 if the file was successfully removed from the file system and returns 0 if the file could not be removed from the file system
- could be unsuccessful for various reasons, including insufficient file permissions or an invalid filename
Example
The following example uses the file() function to verify the existence of a file, and then removes the file using theremove() function. If the file exists but cannot be removed, a message is returned stating that the file properties and user permissions should be checked:
file_name="D:\\temp_data.txt";
if (file(file_name)) {
print("\nFile (".file_name.") exists!\n");
if (remove(file_name)) {
print("\nFile (".file_name.") removed!\n");
} else {
print("\nFile (".file_name.") could not be removed!\n\n".
"Check file properties and user permissions!");
}
} else {
print("\nFile (".file_name.") does not exist!\n");
}
if (file(file_name)) {
print("\nFile (".file_name.") exists!\n");
if (remove(file_name)) {
print("\nFile (".file_name.") removed!\n");
} else {
print("\nFile (".file_name.") could not be removed!\n\n".
"Check file properties and user permissions!");
}
} else {
print("\nFile (".file_name.") does not exist!\n");
}