473,395 Members | 1,702 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,395 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 3456

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
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
by: Tolgay Gl | 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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
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,...
0
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...

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.