473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Determining Directory of Script

Hello,

I am currently running PHP 4.3.2 on Windows NT 4.0.

Is there anyway (I am sure there is but I just can't find it) that you
can determine the path of the current script that is running?

I have created a command line script that processes some files and I
would like to be able to drop the script in a given directory and then
run it from there.

In this manner the "active directory" will change depending upon where
I call the script from. Rather than having to change the script each
time, or having to hard-code a directory in-place, I would rather keep
it dynamic if possible.

Thanks,

Hugh
Jul 17 '05 #1
4 7390
Hugh Cowan:
I am currently running PHP 4.3.2 on Windows NT 4.0.

Is there anyway (I am sure there is but I just can't find it) that you
can determine the path of the current script that is running?


$cwd = dirname(__FILE__);

This works across platforms.

André Nęss
Jul 17 '05 #2

"Hugh Cowan" <hw*****@hotmail.com> wrote in message
news:46**************************@posting.google.c om...
Hello,

I am currently running PHP 4.3.2 on Windows NT 4.0.

Is there anyway (I am sure there is but I just can't find it) that you
can determine the path of the current script that is running?

I have created a command line script that processes some files and I
would like to be able to drop the script in a given directory and then
run it from there.

In this manner the "active directory" will change depending upon where
I call the script from. Rather than having to change the script each
time, or having to hard-code a directory in-place, I would rather keep
it dynamic if possible.

Thanks,

Hugh


Yep - view the output from phpinfo(); and it should help... There are
methods to get the path of your running script in addition to the path of
any file that was included, if it sat in a different folder... Always keep
phpinfo in mind (check its syntax as some of the info you won't need and you
can cut it down a bit with something like phpinfo(INFO_ENVIRONMENT) and
phpinfo(INFO_VARIABLES).... I always find them useful, especially with forms
processing...
Jul 17 '05 #3
Carved in mystic runes upon the very living rock, the last words of Hugh
Cowan of comp.lang.php make plain:
Is there anyway (I am sure there is but I just can't find it) that you
can determine the path of the current script that is running?


It sounds like you'll be using it in a consistent environment, so the
previous suggestions should serve you well, but if not there's always ./

This was something I went round and round with in Phorm, which has to run
on all kinds of different platforms with all kinds of different
configurations; some variables or commands would work in some
circumstances and not in others. I don't know that there is any 100%
cross-platform, cross-configuration way to determine the absolute path of
the script.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #4
André Nęss <an*********************@ifi.uio.no> wrote in message news:<bm**********@maud.ifi.uio.no>...
Hugh Cowan:
I am currently running PHP 4.3.2 on Windows NT 4.0.

Is there anyway (I am sure there is but I just can't find it) that you
can determine the path of the current script that is running?


$cwd = dirname(__FILE__);

This works across platforms.

André Nęss


Thank-you, thank-you, thank-you!!!! Works perfectly -- just what I was
looking for. Thanks so much for the reply and answer. As other
people have posted there are some global variables that contain the
same type of information -- however I cannot seem to get access to
them.

When I run the phpinfo() function and look at the results displayed
there is nothing that shows the current directory, or directory of
current script. I noticed that if I look in the help manual there are
suppose to be a variety of variables that do just that, but I couldn't
find them.

I don't know if it's because I am running on Windows, or because I am
running scripts locally and not through a web-server??

Anyways -- it doesn't matter now, I have my answer and I can stop
pulling my hair out.

Thanks again,

Hugh
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: hokiegal99 | last post by:
How would I determine if a filename is greater than a certain number of characters and then truncate it to that number? For example a file named XXXXXXXXX.txt would become XXXXXX fname = files...
3
by: Peter Schwalm | last post by:
I'd like to modify the python search path depending on the source directory of the script being started. The reason is: I use a version control system, and the python scripts and modules are...
3
by: Dfenestr8 | last post by:
os.listdir("path") returns the names of all the items in a directory ok, but I need to know whether the item is a file or a directory. Can anybody tell me how this could be done?
13
by: Razzbar | last post by:
Is there any to tell via javascript the "state" of a link? I mean, I'd like to be able to tell if a link has been followed or not. (hehe, I can hear shrill crys of "privacy!" in the distance...)
2
by: Phil Galey | last post by:
Using the following, you can determine the size of a file: Dim fi As New IO.FileInfo(<Path to file>) MsgBox(fi.Length) .... but what about the size of a directory? The IO.DirectoryInfo object...
4
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but...
4
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is...
1
by: Marco Shaw | last post by:
Is there something built-in to .net to determine if a directory is writeable by the current user? I want to write a Windows Powershell script that needs to write to a directory. I can certainly...
3
by: Chris Mellon | last post by:
This appears to be a change in behavior from Python 2.4 to Python 2.5, which I can't find documented anywhere. It may be windows only, or related to Windows behavior. In 2.4, the current...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.