File length for fstreams

L

Lilith

I've been working on a program in VC++. The basic operation of the
system I'm working with is that I create a file in on directory, the
system picks it up and generates a report in another directory, which
I then read in and to strip out the information I need. The file I'm
reading is not named with any correlation to the file name I wrote out
so I have to monitor for when a new file appears and check it to make
sure it's the one resulting from my query.

My tactic is to do a findfirst/findnext on all of the existing files
in the directory so I don't have to read through all of them later to
verify that they're either the one I want or not. I then write out my
request and go into a loop waiting for a new file to appear with
either a findfirst or findnext depending on whether or not the
directory may have been empty to begin with.

The crux of my problem is that when the file first shows up it's
likely to have a zero length to it so I need to wait until it's
completely written out and the size shows to be non-zero. Somewhere
in trying to get this all to work I think I'm mangling the file handle
value or at least its effect on the file find mechanism. I can avoid
this if I can get the file length without having to resort to using
the file handle and finddata_t.

So, is there a way to find the length of a file without resorting to
using findfirst/findnext to get information into a finddata_t
structure? I'm using fstream as opposed to FILE or CFile.

TIA,
Lilith
 
A

Artie Gold

Lilith said:
I've been working on a program in VC++. The basic operation of the
system I'm working with is that I create a file in on directory, the
system picks it up and generates a report in another directory, which
I then read in and to strip out the information I need. The file I'm
reading is not named with any correlation to the file name I wrote out
so I have to monitor for when a new file appears and check it to make
sure it's the one resulting from my query.

My tactic is to do a findfirst/findnext on all of the existing files
in the directory so I don't have to read through all of them later to
verify that they're either the one I want or not. I then write out my
request and go into a loop waiting for a new file to appear with
either a findfirst or findnext depending on whether or not the
directory may have been empty to begin with.

The crux of my problem is that when the file first shows up it's
likely to have a zero length to it so I need to wait until it's
completely written out and the size shows to be non-zero. Somewhere
in trying to get this all to work I think I'm mangling the file handle
value or at least its effect on the file find mechanism. I can avoid
this if I can get the file length without having to resort to using
the file handle and finddata_t.

So, is there a way to find the length of a file without resorting to
using findfirst/findnext to get information into a finddata_t
structure? I'm using fstream as opposed to FILE or CFile.

There is no way to do this in standard C++, you'll have to ask in a
Windows newsgroup (there may be a platform specific way, but we can't
discuss it here).

HTH,
--ag
 
L

Lilith

There is no way to do this in standard C++, you'll have to ask in a
Windows newsgroup (there may be a platform specific way, but we can't
discuss it here).

My luck!! :))

Thanks,
Lilith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top