Home: Perl Programming Help: Frequently Asked Questions:
How Do I delete A File?


Dec 12, 2000, 2:50 PM

Views: 9041
How Do I delete A File?

use unlink.

unlink "file.txt";

If the file is located in another directory than the one your script is executing from, then simply specify the full path before the file's name.

unlink "/path/to/file.txt";

To check and see if this code fails, use this

unlink "file.txt" or die "Couldn't Delete File because: $!";

Instead of die you can use print to actually print the message to the screen, when you execute your code through a browser this will help more than die, but the script will continue executing.