Re: How to get file count under a directory?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance





"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


.



Relevant Pages

  • Re: Algorithm to find break in contiguity
    ... save any significant time by jumping around doing a binary search, ... the missing number hasn't been reached yet) as you are reading. ... If the data is not already in sequence, ... Since you used the word "contiguity" in the Subject field, ...
    (comp.programming)
  • Re: How to get file count under a directory?
    ... rockdale wrote: ... what is the largest sequence number of my log file. ... a loop from 1 to like 100000, check if the file exist, if it does ...
    (microsoft.public.vc.language)
  • Re: How to get file count under a directory?
    ... what is the largest sequence number of my log file. ... in a loop from 1 to like 100000, check if the file exist, if it does ... You can simply enumerate all these files. ... Yes but a binary search is probably faster. ...
    (microsoft.public.vc.language)
  • Re: Finding a maxima with binary search?
    ... >> decreasing integers, then the first difference tells which way. ... Try the sequence: ... I suspect you could modify the basic approach of a binary search ...
    (comp.programming)
  • Re: Cobol Linear search Vs Perfrom Until
    ... Glenn Someone wrote ... > SEARCH ALL doesn't cut it, provide a binary search, it's not that hard ... Adding the sequence and then SEARCH ALL '0' gives a reliable, ... _defined_ result of the first entry for without having ...
    (comp.lang.cobol)