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

I have files on a server that I need to move around and or delete. I was wondering why if I used the server name and not a drive unlink returns a 0? Here is a simple example that i have run. When i use the C or Q drive it works correctly however when i use \\fileserver it does not.
use file::Copy; my $testfile; my $rtn; $testfile = "\\\\fileprint-01\\Company\\HFACCE~1\\IT\\dev\\test\\test. +txt"; #$testfile = "Q:\\Company\\HFACCE~1\\IT\\dev\\test\\test.txt"; #$testfile = "C:\\temp\\test.txt"; print $testfile . "\n"; $rtn = unlink $testfile; print $rtn;

Replies are listed 'Best First'.
Re: unlink a server file
by jettero (Monsignor) on May 22, 2009 at 14:49 UTC

    You should check out autodie. Otherwise, choose ...

    unlink $file or die "couldn't delete $file: $!"
    ... for an explanation of the failure.

    -Paul

Re: unlink a server file
by ikegami (Patriarch) on May 22, 2009 at 15:09 UTC

    Works fine for me. Use

    unlink($file) or die("Can't unlink $file: $!\n");

    to find the cause of your failure. A permission problem, perhaps?

Re: unlink a server file
by jonschin (Novice) on May 22, 2009 at 16:16 UTC
    I understand the permissions issue and did some investigating through the command line.
    Z:\HF ACCESS\IT\dev>perl testdel.pl \\fileprint-01\Company\HFACCE~1\IT\dev\test\test.txt couldn't delete \\fileprint-01\Company\HFACCE~1\IT\dev\test\test.txt: +Permission denied at testdel.pl line 12.
    this is telling me permission problem. And when I dir that folder using the full path and try to del it gives me this
    Z:\HF ACCESS\IT\dev>dir \\fileprint-01\Company\HFACCE~1\IT\dev\test\t +est.txt Volume in drive \\fileprint-01\Company is Data Volume Serial Number is C8C5-EF0A Directory of \\fileprint-01\Company\HFACCE~1\IT\dev\test 05/22/2009 10:21 AM 0 test.txt 1 File(s) 0 bytes 0 Dir(s) 196,346,269,696 bytes free Z:\HF ACCESS\IT\dev>del \\fileprint-01\Company\HFACCE~1\IT\dev\test\t +est.txt \\fileprint-01\Company\HFACCE~1\IT\dev\test\test.txt Access is denied.
    This is where it gets tricky when I change the path to the long name and put quotes around the path it allows me to delete the file
    Z:\HF ACCESS\IT\dev>del "\\fileprint-01\data\company\hf access\it\dev\ +test\test.txt"
    I verified this with another file test.tst.txt after
    Z:\HF ACCESS\IT\dev>dir \\fileprint-01\Company\HFACCE~1\IT\dev\test\t +est.tst.txt Volume in drive \\fileprint-01\Company is Data Volume Serial Number is C8C5-EF0A Directory of \\fileprint-01\Company\HFACCE~1\IT\dev\test 05/22/2009 11:27 AM 0 test.tst.txt 1 File(s) 0 bytes 0 Dir(s) 194,855,174,144 bytes free Z:\HF ACCESS\IT\dev>del \\fileprint-01\Company\HFACCE~1\IT\dev\test\ +test.tst.txt \\fileprint-01\Company\HFACCE~1\IT\dev\test\test.tst.txt Access is denied.
    Now when I tried putting this into play with perl and unlink this is what I recieved.
    Z:\HF ACCESS\IT\dev>perl testdel.pl "\\fileprint-01\Company\HF ACCESS\IT\dev\test\test.tst.txt" couldn't delete "\\fileprint-01\Company\HF ACCESS\IT\dev\test\test.tst +.txt": No such file or directory at testdel.pl line 12. Z:\HF ACCESS\IT\dev>dir "\\fileprint-01\Company\HF ACCESS\IT\dev\test\ +test.tst.txt" Volume in drive \\fileprint-01\Company is Data Volume Serial Number is C8C5-EF0A Directory of \\fileprint-01\Company\HF ACCESS\IT\dev\test 05/22/2009 11:27 AM 0 test.tst.txt 1 File(s) 0 bytes 0 Dir(s) 194,891,591,680 bytes free Z:\HF ACCESS\IT\dev>perl testdel.pl \\fileprint-01\Company\HF ACCESS\IT\dev\test\test.tst.txt couldn't delete \\fileprint-01\Company\HF ACCESS\IT\dev\test\test.tst. +txt: Permission denied at testdel.pl line 12.
    In the script I inserted quotes around the file name for the first run and removed them for the second because that is what did it for del in the command prompt. What am i missing about unlink, why when I use quotes it tells me that it does not exist and when I don't it tells me permission denied.

      You say the following works:

      Z:\HF ACCESS\IT\dev>del "\\fileprint-01\data\company\hf access\it\dev\ +test\test.txt"

      But in all your examples that don't work the path is different - they don't have "data" after the server name. Could this be your problem?

        yes I could see how that would be confusing. data is the parent folder of company however both are shared on the server so both work just as well. Good thought though. I appreciate you looking at it.

      Now when I tried putting this into play with perl and unlink this is what I recieved.

      On the command line, the quotes are used to tell the command line parser where the argument ends. They are not part of the file name and should not be passed to unlink.

Re: unlink a server file
by Anonymous Monk on May 22, 2009 at 14:59 UTC
    use file::Copy; Module names are case-sensitive
Re: unlink a server file
by Bloodnok (Vicar) on May 22, 2009 at 15:03 UTC
    ...and your problem is ????

    Permissions prevent server-based file deletion or moving by a client process, via a networked filesystem protocol.

    However, M$ appear to have modified this behaviour when mapping so-called network drives - presumably because a) they can and b) it suits them to.

    A user level that continues to overstate my experience :-))