Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 5th, 2005, 11:50 AM   #1
Blackwolf189
Newbie
 
Join Date: May 2005
Posts: 10
Rep Power: 0 Blackwolf189 is on a distinguished road
Get Current Directory Of Script

can someone tell me a way to get the directory that the script is in from within the program?
Blackwolf189 is offline   Reply With Quote
Old Nov 5th, 2005, 12:33 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
[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.
__________________

tempest is offline   Reply With Quote
Old Nov 5th, 2005, 1:14 PM   #3
Blackwolf189
Newbie
 
Join Date: May 2005
Posts: 10
Rep Power: 0 Blackwolf189 is on a distinguished road
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
Blackwolf189 is offline   Reply With Quote
Old Nov 8th, 2005, 12:02 AM   #4
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
look into CWD .... http://search.cpan.org/~kwilliams/Cwd-2.21/Cwd.pm
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Old Nov 8th, 2005, 4:17 PM   #5
Blackwolf189
Newbie
 
Join Date: May 2005
Posts: 10
Rep Power: 0 Blackwolf189 is on a distinguished road
I have seen CWD but it doesnt return the directory the script is in just the current working directory which isnt the same thing
Blackwolf189 is offline   Reply With Quote
Old Nov 8th, 2005, 4:20 PM   #6
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Isn't the program path and name in $0 or $$ or $_ or one of those special variables?
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Nov 8th, 2005, 4:51 PM   #7
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 3 2roll4life7 is on a distinguished road
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.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 8th, 2005, 5:05 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
There may be something in a Win32 specific module that finds the path.
Arevos is offline   Reply With Quote
Old Nov 8th, 2005, 5:28 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Investigate GetFullPathName. Don't know that it's precisely what you're looking for.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 8th, 2005, 6:05 PM   #10
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 3 Kaja Fumei is on a distinguished road
$ENV{'SCRIPT_NAME'} contains the name of the current running script as well as the full path. You could extract the path from that.
Kaja Fumei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:06 PM.

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