Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Get Current Directory Of Script (http://www.programmingforums.org/showthread.php?t=6842)

Blackwolf189 Nov 5th, 2005 12:50 PM

Get Current Directory Of Script
 
can someone tell me a way to get the directory that the script is in from within the program?

tempest Nov 5th, 2005 1:33 PM

[php]
#!/usr/bin/perl
$pwd = "";
open(getPwd, "/bin/pwd |");
while(<getPwd>) {
$pwd .= $_;
}
close getPwd;

print "The working directory is, " . $pwd;
[/php]

There is probably a much simpler way, my perl skills are rudimentary.

Blackwolf189 Nov 5th, 2005 2:14 PM

Im using windows and I cant follow what your script is supposed to do. It didn't work for me, can you explain your thought process

sykkn Nov 8th, 2005 1:02 AM

look into CWD .... http://search.cpan.org/~kwilliams/Cwd-2.21/Cwd.pm

Blackwolf189 Nov 8th, 2005 5:17 PM

I have seen CWD but it doesnt return the directory the script is in just the current working directory which isnt the same thing

iignotus Nov 8th, 2005 5:20 PM

Isn't the program path and name in $0 or $$ or $_ or one of those special variables?

2roll4life7 Nov 8th, 2005 5:51 PM

Quote:

Originally Posted by iignotus
Isn't the program path and name in $0 or $$ or $_ or one of those special variables?

Yeah, $0 holds the the programs own name, which may contain the path (it varies). $$ is the process ID number.

Arevos Nov 8th, 2005 6:05 PM

There may be something in a Win32 specific module that finds the path.

DaWei Nov 8th, 2005 6:28 PM

Investigate GetFullPathName. Don't know that it's precisely what you're looking for.

Kaja Fumei Nov 8th, 2005 7:05 PM

$ENV{'SCRIPT_NAME'} contains the name of the current running script as well as the full path. You could extract the path from that.


All times are GMT -5. The time now is 8:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC