Deleting files with unlink()

To delete files, simply pass a filename string as the only parameter to unlink(). Note that unlink deals only with files - to delete directories you need rmdir().

    if (unlink($filename)) {
        print "Deleted $filename!\n";
    } else {
        print "Delete of $filename failed!\n";

Author's Note: if you have a file opened with fopen(), you need to fclose() it before you call unlink()


Next chapter: Temporary files >>

Previous chapter: Copying files with copy()

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.