Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Working directory oddity

by sg (Pilgrim)
on Oct 19, 2007 at 06:02 UTC ( [id://645901]=note: print w/replies, xml ) Need Help??


in reply to Re: Working directory oddity
in thread Working directory oddity

I ran into a similar problem recently. I believe the issue mentioned in the original post "but it returns the directory exectly the way it was typed" is referred to by Microsoft as the feature of being "case insensitive but case preserving". By "case preserving" they do not seem to mean that they preserve the case of the file (or directory) to the case that was used when it was created but that they preserve the case as was used when it was accessed; this is a weird feature.

The "use Win32" solution means that one needs to branch the user-script based on the OS. I tried to solve the problem using

use Cwd qw(getcwd chdir realpath); use File::Spec::Functions; # canonpath

but was not successful -- even canonpath(realpath()) respects the "case preserving" "feature".

Replies are listed 'Best First'.
Re^3: Working directory oddity
by ikegami (Patriarch) on Oct 19, 2007 at 06:10 UTC

    Using the same path you provided avoids confusion. Unix usually does the same thing. If you use /home/ikegami/symlink/dir, it won't magically become /some/where/else/dir.

    File::Spec definitely won't help, since it doesn't do any system calls.

    You could always do a directory listing for every component of the path and look for the matching name. That can fail due to permissions and if one of the components is an 8.3 name, but you can always fall back to what you were provided for those components.

    Finally, so what if you have to branch. You're asking to do something platform-specific, after all. Just hide it in a module with a thin, portable interface. It can call Win32::GetLongPathName on Windows and File::Spec->canonpath on other platforms.

      I was using File::Spec with Cwd. Isn't the purpose of Cwd, especially its realpath, to be "the hiding module" suggested above?

        Yes, that does sounds like a good place for it. You could submit a patch to add this function to Cwd.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found