in reply to Re: File::Find problems
in thread File::Find problems

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.

Replies are listed 'Best First'.
Re^3: File::Find problems
by ikegami (Patriarch) on Jan 15, 2010 at 08:10 UTC

    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.

Re^3: File::Find problems
by ikegami (Patriarch) on Jan 15, 2010 at 08:13 UTC

    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
        What command line? I thought you were using rename
        rename($_, "/Users/me/Pictures/a b c d/$_")