
japhy
Enthusiast
Jan 28, 2000, 6:39 PM
Post #6 of 10
(666 views)
|
|
Re: translating relative pathname to absolute path
[In reply to]
|
Can't Post
|
|
I think there is a module to do this, but I don't know its name. For Windows, it's as easy as string manipulation, because there aren't symbolic links (directories which take you to other directories, really): <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # Perl and Windows can understand /'s $path = "c:/foo/this/that/../../those/../mine"; 1 while $path =~ s{ [^/]+ /\.\./ }{}xg; </pre><HR></BLOCKQUOTE> The regex removes directory names followed by the .. directory. You need to do this as a while-loop, because after it's removed "that/../", it's too far ahead to see that the string now holds "this/../". If you're interested in seeing a Unix solution (that honors symlinks), I'll post one, but only after I think it through and stress test it.
|