Page 1 of 1

How to find the path of a specific file?

Posted: Wed Jun 11, 2008 8:17 pm
by Ghe
Good Day to all,

Ahm, does anyone here know how can i make a function that get the filepath of a specific file?

I want to create a function like this:
- getFilePath('A_file_with_an_unknown_path.inc');
then the function will return the path of the file with an unknown path/directory.

Is this possible? If not, can anyone tell me how can I be able to include a file with an unknown filepath/directory?

- require_once('???/???/???/A_file_with_an_unknown_path.inc');

Please help.

Thank you in advance.

Re: How to find the path of a specific file?

Posted: Wed Jun 11, 2008 8:55 pm
by superdezign
The only way to do this is to know the path and directory.
I have no idea why you would want to do this, or how you would go about finding a random file in a file system, but if you know the location of the file in relativity to the file that is including it, using dirname() in combination with the __FILE__ constant can give you the current directory.

Re: How to find the path of a specific file?

Posted: Wed Jun 11, 2008 9:50 pm
by hansford
or you could write an entire program for searching all of the dir and files on your server. Sounds like alot of work to me.

Re: How to find the path of a specific file?

Posted: Thu Jun 12, 2008 2:19 am
by Ghe
Oh, i see, thank you for the reply.

Re: How to find the path of a specific file?

Posted: Thu Jun 12, 2008 9:40 am
by pickle
You could use getcwd() to get your current directory, then tack on the part of the filename you know, then run that through realpath().