in reply to Re: how to get the current folder name where the program is running?
in thread how to get the current folder name where the program is running?

To ammend your reply, use $0 (which the parent did), not cwd() (which many recommend), since $0 has the full name of the running script and cwd is where the script was run from. If you aren't in that directory where it was run, cwd fails miserably.

From perlvar....

$0 Contains the name of the program being executed. On some oper- ating systems assigning to `$0' modifies the argument area that the ps program sees. This is more useful as a way of indicat- ing the current program state than it is for hiding the program you're running. (Mnemonic: same as sh and ksh.)

Update: Ug.. as tachyon showed, it doesn't always work. Try /procfs, it should tell you what file you are currently running.. though windows and osx doesn't have that.


Play that funky music white boy..
  • Comment on Re: Re: how to get the current folder name where the program is running?

Replies are listed 'Best First'.
Re: Re: Re: how to get the current folder name where the program is running?
by tachyon (Chancellor) on Dec 13, 2003 at 14:00 UTC

    So you tested this right?

    [root@smart sporty]# pwd /root/sporty [root@smart sporty]# cat uhuh.pl #!/usr/bin/perl print "$0 does not know\n", `pwd`; [root@smart sporty]# ./uhuh.pl ./uhuh.pl does not know /root/sporty [root@smart sporty]# perl uhuh.pl uhuh.pl does not know /root/sporty [root@smart sporty]#

    If you aren't in that directory where it was run, cwd fails miserably.

    And if (you) don't call the script with /full/path/to/script.pl then $0 has little to offer....

    cheers

    tachyon

      There's always procfs.. but that's very OS dependent.

      Play that funky music white boy..