in reply to File::Find problems

As a result, I am getting a no such directory error when I try to rename(move) filename.

Not true. rename doesn't care about the doubled slash, because the system doesn't care about the doubled slash.

$ mkdir -p x/x $ perl -e'rename "x//x", "x//y" or die' $ ls -l x total 4 drwx------ 2 ikegami pg1404028 4096 2010-01-14 23:55 y

Also tested on Windows.

Replies are listed 'Best First'.
Re^2: File::Find problems
by 7stud (Deacon) on Jan 15, 2010 at 08:06 UTC

    Yes, I've decided I have NO IDEA how to deal with path names containing spaces. I also think the error given by rename() sucks: it doesn't tell you which path is faulty.

    I've performed "thousands" of tests, trying to figure out what is happening with my script to no avail. All I am trying to do is move some files from an external usb drive to a directory on my computer that I enter on the command line when prompted.

    I can't make heads or tails out of what's happening. When I print out $File::Find::name, I get this:

    /Volumes/Volume Name/A/B/filename
    That seems like a faulty path to me because the space in "Volume Name" is not escaped.

      That seems like a faulty path to me because the space in "Volume Name" is not escaped.

      Why would you expect something other than a path from File::Find? It was escaped, it wouldn't be a path.

      You need to escape something when you want to embed one thing into another. (A path in a glob pattern, a string in Perl code, a string in a command line, etc) How you escape it also dependent on what you want to embed it into. Once it's escaped, it's no longer a path. (It's a glob pattern, a Perl string literal, a shell string literal, etc)

      Yes, I've decided I have NO IDEA how to deal with path names containing spaces

      In a glob pattern? You've already been given two solutions. Escape the space or use bsd_glob.

      I also think the error given by rename() sucks: it doesn't tell you which path is faulty.

      It's not like you checking two paths is harder than checking one when you have a problem.

      The system simply returns a number which represents the error message.

      That seems like a faulty path to me because the space in "Volume Name" is not escaped.

      Why would you expect something other than a path from File::Find? It was escaped, it wouldn't be a path.

      You need to escape something when you want to embed one thing into another. (A path in a glob pattern, a string in Perl code, a string in a command line, etc) How you escape it also dependent on what you want to embed it into. Once it's escaped, it's no longer a path. (It's a glob pattern, a Perl string literal, a shell string literal, etc)

      Yes, I've decided I have NO IDEA how to deal with path names containing spaces

      In a glob pattern? You've already been given two solutions. Escape the space or use bsd_glob.

      I also think the error given by rename() sucks: it doesn't tell you which path is faulty.

      It's not like you checking two paths is harder than checking one when you have a problem.

      The system simply returns a number which represents the error message.

        First of all, I shouldn't even have to worry about the full path when using File::Find, right? The docs say, that File::Find uses chdir() to switch to the directory of the file. So, shouldn't I be able to use $_ inside wanted() as the oldname argument for rename()?

        That would leave me with a single path to worry about. In that case what do I need to enter on the command line to move the file to the directory:

        /Users/me/Pictures/a b c d