Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem deleting files. Ive used unlink() before and it has worked fine, but although it appears to be working (i.e. not entering my error routine) the file remains where it is.

I thought it was a permissions issue before, so I gave the file 777 permissions, but its still not budging.

Anyone able to cast any light on this?

Many Thanks,
Rob.

Replies are listed 'Best First'.
Re: Deleting files problem
by Zaxo (Archbishop) on Jun 23, 2003 at 13:42 UTC

    Do you have write permission for the directory? To unlink a file, the directory inode is written.

    After Compline,
    Zaxo

      Yes, the directory also has permissions of 777.
Re: Deleting files problem
by Lachesis (Friar) on Jun 23, 2003 at 13:46 UTC
    You should Check what you get back from unlink.
    unlink 'foo' or die "Delete of foo failed - $!";
    To unlink a file you will need write permissions for the directory it is in so that will be the best thing for you to check.
      Bizarrely, after adding an "or die" statement, its not dying (as it wasnt before), but now it is deleting the file.

      How oddbr>
      Cheers for your help guys.
Re: Deleting files problem
by Tomte (Priest) on Jun 23, 2003 at 13:42 UTC

    Whithout code?
    I certainly can't...

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: Deleting files problem
by Anonymous Monk on Jun 23, 2003 at 13:45 UTC
    Sorry, this thing is frying my brain.

    $editme = "/path/to/file.jpg";
    unlink $editme;

      Check the whole path, I tested it, seems like you need access rights (x) to all directories in the path.

      mkdir -p noaccess/access touch noaccess/access/delete.me chmod u-x noaccess/ perl -e 'unlink("/home/tom/scratch/perl/noaccess/access/delete.me") or + die("oops $!")' oops Permission denied at -e line 1. chmod u+x noaccess/ perl -e 'unlink("/home/tom/scratch/perl/noaccess/access/delete.me") or + die("oops $!")'

      regards,
      tomte


      Hlade's Law:

      If you have a difficult task, give it to a lazy person --
      they will find an easier way to do it.