Module/recipe to resolve full pathnames?

K

kj

Is there a module (or built-in) that will take an arbitary Unix
filename specification (either absolute or relative) and return
the "canonical" absolute full path to the file? For example:

input: ~jones/../foo/../../bar/./baz//frobozz/
output: /bar/baz/frobozz

(where, in this case /bar/baz/frobozz is actually a directory).

TIA!

kj
 
R

Richard Morse

kj <[email protected]> said:
Is there a module (or built-in) that will take an arbitary Unix
filename specification (either absolute or relative) and return
the "canonical" absolute full path to the file? For example:

input: ~jones/../foo/../../bar/./baz//frobozz/
output: /bar/baz/frobozz

(where, in this case /bar/baz/frobozz is actually a directory).

Try File::Spec (or, more exactly, File::Spec::Unix).

HTH,
Ricky
 
T

Tulan W. Hu

kj said:
Is there a module (or built-in) that will take an arbitary Unix
filename specification (either absolute or relative) and return
the "canonical" absolute full path to the file? For example:

input: ~jones/../foo/../../bar/./baz//frobozz/
output: /bar/baz/frobozz

chdir($input);
$a=`pwd`;
 
D

Darren Dunham

Is there a module (or built-in) that will take an arbitary Unix
filename specification (either absolute or relative) and return
the "canonical" absolute full path to the file? For example:
input: ~jones/../foo/../../bar/./baz//frobozz/
output: /bar/baz/frobozz

Do you want this to occur symbolically or by running the filesystem?
Each has disadvantages.

Running the filesystem is usually slower and it assumes you have actual
permissions (and connectivity) to follow along.

Doing that symbolically assumes that none of the components are symlinks
to other locations. Due to that, the '..' components may not be the
same as the pre-link parent.

"./foo/../bar" does not have to be the same as "./bar".

Because of this, I think File::Spec does things symbolically, but it
then must leave in ".." components.

$ cd /usr/bin
$ perl -e 'use File::Spec; $a = "foo/../bar" ; print File::Spec->rel2abs($a);'
/usr/bin/foo/../bar
 
B

Ben Morrow

Quoth Darren Dunham said:
Do you want this to occur symbolically or by running the filesystem?
Each has disadvantages.
<snip>

File::Spec will resolve logically, as you say; Cwd will resolve
physically (including symlinks).

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,154
Messages
2,570,870
Members
47,400
Latest member
FloridaFvt

Latest Threads

Top