ciryon has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow Monks!

Short question:

If I know a relative path like /my/random/../path/file.txt can I convert it to an absolute path like /my/path/file.txt in this example?

Thanks.

Replies are listed 'Best First'.
Re: Relative to absolute path
by grinder (Bishop) on Jul 12, 2004 at 08:01 UTC

    This is a FAQ.

    Typing "relative absolute" into the search box above yields a few threads, of which I can especially recommend:

    More searching will turn up other nodes on the same question but I think that one has all the answers you want.

    - another intruder with the mooring of the heat of the Perl

      Thanks, my bad.

      All that I needed was actually:

      $listdirectory = Win32::GetFullPathName("$ARGV[0]\\..\\listfiles");

      Thanks again.

        Don't use Win32::API, use File::Spec. It is portable and standard.
Re: Relative to absolute path
by stajich (Chaplain) on Jul 12, 2004 at 12:37 UTC
    I use File::Spec.
    use File::Spec; my $abspath = File::Spec->rel2abs($relpath);
    Also see the canonpath() method for cleaning up extra slashes.
Re: Relative to absolute path
by rrwo (Friar) on Jul 12, 2004 at 20:36 UTC

    Take a look at File::Spec. There is a canonpath (canonical path) functuon that should clean up a path like that, as well as a rel2abs function that should convert it to an absolute path.