By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,165 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,165 IT Pros & Developers. It's quick & easy.

Open file without know the complete name?

P: n/a
nan

Hi all.
Anyone has an idea of how to open a file without know the complete
name of it, without opening the directory (with opendir) and test each
file?

For example, I have this:

1070471736268

and the complete file name is:

1070471736268-E1=E9=ED=F3.txt

Regards and thanks for you comments.

Antonio.
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In <20***************************************@yahoo.e s> nan <an*******************@yahoo.es> writes:

Anyone has an idea of how to open a file without know the complete
name of it, without opening the directory (with opendir) and test each
file?

For example, I have this:

1070471736268

and the complete file name is:

1070471736268-E1=E9=ED=F3.txt


This cannot be done in standard C, because fopen() doesn't accept
wildcard characters. A directory lookup must be performed, one way or
another, to obtain the complete file name.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #2

P: n/a
On Thu, 4 Dec 2003, nan wrote:

Hi all.
Anyone has an idea of how to open a file without know the complete
name of it, without opening the directory (with opendir) and test each
file?

For example, I have this:

1070471736268

and the complete file name is:

1070471736268-E1=E9=ED=F3.txt

Regards and thanks for you comments.


So you want to open a file name but:

1) you don't know its full name
2) you cannot scan the directory for the file name

Sure, I know that FILENAME_MAX is the longest a file name can be. I can
just iterate through all possible combinations of strings. If I know it
starts with a 13 character string them I want to start with that string
then all strings of length 14, 15, 16, etc. For each filename generated I
would attempt to open the file.

I, personally, would never do this. I'd use an implementation defined way
of scanning the directory.

Your question is equivalent to, "I have a word written on a piece of
paper. It starts with 'pro'. Tell me what the word is but you cannot look
at the piece of paper." This is actually easier because you can use a
dictionary to filter your guesses.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 13 '05 #3

P: n/a
nan wrote:

Hi all.
Anyone has an idea of how to open a file without know the complete
name of it, without opening the directory (with opendir) and test each
file?

For example, I have this:

1070471736268

and the complete file name is:

1070471736268-E1=E9=ED=F3.txt

Regards and thanks for you comments.

Not in C but, if your program is named foo you might invoke it..

$foo 1070471736268*.txt

Your command processor might well present to your program the names of
all the files in the current directory which begin with the number and
have a .txt extension. Think argc and argv.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 13 '05 #4

P: n/a
In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
nan wrote:

Hi all.
Anyone has an idea of how to open a file without know the complete
name of it, without opening the directory (with opendir) and test each
file?

For example, I have this:

1070471736268

and the complete file name is:

1070471736268-E1=E9=ED=F3.txt

Regards and thanks for you comments.

Not in C but, if your program is named foo you might invoke it..

$foo 1070471736268*.txt

Your command processor might well present to your program the names of
all the files in the current directory which begin with the number and
have a .txt extension. Think argc and argv.


But it might as well not do that. It's Unix shells that typically
expand wildcards on the command line, but most other command processors
don't do it. On some implementations, it is programmer's option (usually
via a global variable or by linking an alternate crt0) whether the C
startup code will do it or not.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.