473,509 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3458

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
16599
by: o'seally | last post by:
solaris/linux admins/rookie_developers that battle with this error are probably all frustrated when it happens. i bet you're also somehow frustrated by this seemingly unsolvable error :-) ...take...
2
2136
by: Tolgay Gül | last post by:
When we are search google our keywords . google get some our page. Our home page name is index.html index html include left and right html. so google get left or right html. and we would like if...
11
12778
by: Ahmet AKGUN | last post by:
Hi; is it possible to open one form in .net platform that we have its name in string ? I have string sFormName = "frmCustomer"; and I must automatically open Customer form. or is it...
11
3570
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
2
1886
by: JohnGoogle | last post by:
Hi, This is a novists question so please bear with me! I downloaded a test C# project from 'The Code Project' internet site. Unzipped the project to my local folder 'C:\Test'. When I open the...
2
3107
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this,...
0
3749
by: aarthiraaj | last post by:
In my user screen I have view link, if I click this link it will go to servlet and open one word document. It is opening properly, but while opening the attachment it generate one dialog box like...
34
5297
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
185
6853
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
7233
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
7135
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...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.