471,893 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

opening a file when you do not know the full name

I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

I sure don't want to troll through the entire directory with
readdir.

I would appreciate suggestions.

bill
Dec 2 '06 #1
4 3373

bill wrote:
I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

I sure don't want to troll through the entire directory with
readdir.

I would appreciate suggestions.

bill
If you use the "find" command with exec() you can get a list of files
that match your criteria. Essentially using the filename you already
know, and then a wildcard for the extension...

find /var/www/directory/pics2 -name "weddingphoto.*"

For me this outputs: /var/www/directory/pics2/weddingphoto.jpg

If you output the results into a file or into a variable, you can then
parse it for whatever is relevent to you.

find /var/www/directory/pics2 -name "weddingphoto.*" >
/var/www/directory/pics2/results.txt

Dec 2 '06 #2
..oO(bill)
>I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.
http://www.php.net/glob

Micha
Dec 3 '06 #3
Michael Fesser wrote:
.oO(bill)
I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

http://www.php.net/glob

Micha
Not so sure that I agree using a function in an application, that
communicates with the OS via a webserver, is a better choice than
something native to the operating system, but this solution will
definitely work. Probably easier to handle the result set too.

Dec 4 '06 #4
pangea33 wrote:
Michael Fesser wrote:
>.oO(bill)
>>I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.
http://www.php.net/glob

Micha

Not so sure that I agree using a function in an application, that
communicates with the OS via a webserver, is a better choice than
something native to the operating system, but this solution will
definitely work. Probably easier to handle the result set too.
In my case where there is only one result, should work a treat.

Thanks

bill
Dec 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Ahmet AKGUN | last post: by
11 posts views Thread by aldrin | last post: by
2 posts views Thread by JohnGoogle | last post: by
185 posts views Thread by jacob navia | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.