Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: unlink fails to delete files with perculiar names

by BrowserUk (Pope)
on Nov 22, 2011 at 09:51 UTC ( #939410=note: print w/ replies, xml ) Need Help??


in reply to unlink fails to delete files with perculiar names

If you had warnings enabled, you'd see that part of your filename is being taken as a perl variable for interpolation:

$targ = "D:/Users/Dave/Documents/Personal/CV/~$rriculum Vitae - 09 Jun +e 2007.doc";; Use of uninitialized value $rriculum in concatenation (.) or string at + (eval 17) line 1, <STDIN> line 10.

Just escape the $ with \:

$targ = "D:/Users/Dave/Documents/Personal/CV/~\$rriculum Vitae - 09 Ju +ne 2007.doc";;

And the subsequent unlink will likely work.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: unlink fails to delete files with perculiar names
by Eliya (Vicar) on Nov 22, 2011 at 10:45 UTC

    The OP doesn't say how $targ was set.  It's merely speculation that he assigned it using a double-quoted literal. It might just as well have come from a readdir or whatever.

    Also, why would unlink have returned 1, as the OP states? That should only have happened in the (unlikely) case there also was a file 'D:/Users/Dave/Documents/Personal/CV/~ Vitae - 09 June 2007.doc' around at the time of the unlink call.

      It's merely speculation that he assigned it using a double-quoted literal

      Agreed. That's why likely work.

      It might just as well have come from a readdir

      But don't you have to combine the values from readdir with the path in order to get a fully qualified path?

      Could he be doing something like  $targ = "$path/$fname";?

      why would unlink have returned 1, as the OP states?

      Not sure, but that construct looks suspect to me: my($no) = unlink $targ || carp "Unable to delete file $targ\n";.

      What ends up in $no if unlink returns 0; the return value from carp()?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Yup
        $ perl -MCarp -e " my $f = unlink (666) || carp 1; die $f " 1 at -e line 1 1 at -e line 1.

      in my full code I get the file name using File::Find. From a windows directory listing from the command line the file is invisible, also from an explorer window...and from the application (MS word in this case) that presumeably created this as a temporary file it is also invisible.

Re^2: unlink fails to delete files with perculiar names
by DaveARoberts (Acolyte) on Nov 22, 2011 at 16:34 UTC

    I tried escaping the $ with a \

    that did not work ....

      Then I suggest you try del "D:\Users\Dave\Documents\Personal\CV\~$rriculum Vitae - 09 June 2007.doc" on a command line and see what error message is produced by the shell.

      Update: Having seen one of your other replies, try doing:

      attrib -h -s -r "D:\Users\Dave\Documents\Personal\CV\~$rriculum Vitae +- 09 June 2007.doc"

      And then the unlink or del.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2016-07-28 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (259 votes). Check out past polls.