Re: How to get file count under a directory?
- From: "Ben Voigt [C++ MVP]" <bvoigt@xxxxxxxxxxxxxxxx>
- Date: Tue, 29 Sep 2009 17:44:41 -0500
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message news:ecq2xDGQKHA.5108@xxxxxxxxxxxxxxxxxxxxxxx
rockdale <rockdale.green@xxxxxxxxx> wrote:Now the problem is if my application get restarted, I need to know
what is the largest sequence number of my log file. I am thinking in
a loop from 1 to like 100000, check if the file exist, if it does
not , then I get the max sequence number I need. But this method
looks
very awkward. Is there another way to do this(get the max number for
a
series of similar files)?
You can simply enumerate all these files. See FindFirstFile, FindNextFile, FindClose.
Yes but a binary search is probably faster. He'll need at most 17 checks to find the file count up to 128*1024. (Since NTFS uses a B+ tree, trying to open a particular filename won't involve a linear search through the whole list. But the indexing ought to provide a very fast answer to the question, except there's no API to say "find the file named logZZZZZZ, now what's the name of the file before it".)
--.
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
- Follow-Ups:
- Re: How to get file count under a directory?
- From: Carl Daniel [VC++ MVP]
- Re: How to get file count under a directory?
- References:
- How to get file count under a directory?
- From: rockdale
- Re: How to get file count under a directory?
- From: Igor Tandetnik
- How to get file count under a directory?
- Prev by Date: Re: IsTextUnicode?
- Next by Date: Re: Why does fwrite() behave like this?
- Previous by thread: Re: How to get file count under a directory?
- Next by thread: Re: How to get file count under a directory?
- Index(es):
Relevant Pages
|