Home All Groups Group Topic Archive Search About

Programmatically Determining File Size and/or contents

Author
1 Jun 2009 4:31 PM
Rob
I have a VB6 program that I need to make modifications to so that it can
determine the file size of a txt file that is downloaded to a folder (by a
separate process).  This other process will put the file in this location
whether or not it has any records in it.  Is there a way to programmitically
determine if the file is empty, so as I can skip trying to read and process
an empty file?

Thanks

Author
1 Jun 2009 4:41 PM
Nobody
"Rob" <R**@discussions.microsoft.com> wrote in message
news:02785FD4-D0CA-4074-81F5-2FC3BE8EFF23@microsoft.com...
>I have a VB6 program that I need to make modifications to so that it can
> determine the file size of a txt file that is downloaded to a folder (by a
> separate process).  This other process will put the file in this location
> whether or not it has any records in it.  Is there a way to
> programmitically
> determine if the file is empty, so as I can skip trying to read and
> process
> an empty file?

See FindFirstChangeNotification() in MSDN. Here is a VB6 sample:

http://vbnet.mvps.org/code/fileapi/watchedfolder.htm
Author
1 Jun 2009 5:17 PM
Rick Raisley
"Rob" <R**@discussions.microsoft.com> wrote in message
news:02785FD4-D0CA-4074-81F5-2FC3BE8EFF23@microsoft.com...
>I have a VB6 program that I need to make modifications to so that it can
> determine the file size of a txt file that is downloaded to a folder (by a
> separate process).  This other process will put the file in this location
> whether or not it has any records in it.  Is there a way to
> programmitically
> determine if the file is empty, so as I can skip trying to read and
> process
> an empty file?
>


A truly empty TEXT file will have no characters, and therefore zero bytes,
no? That being the case, FileLen would appear to give you what you want: the
size of the file in bytes, and if zero, an empty file.

--
Regards,

Rick Raisley
heavymetal-A-T-bellsouth-D-O-T-net
Author
1 Jun 2009 6:41 PM
Bee
FileLen is limited to Long, so will fail for large files.


Show quoteHide quote
"Rick Raisley" wrote:

> "Rob" <R**@discussions.microsoft.com> wrote in message
> news:02785FD4-D0CA-4074-81F5-2FC3BE8EFF23@microsoft.com...
> >I have a VB6 program that I need to make modifications to so that it can
> > determine the file size of a txt file that is downloaded to a folder (by a
> > separate process).  This other process will put the file in this location
> > whether or not it has any records in it.  Is there a way to
> > programmitically
> > determine if the file is empty, so as I can skip trying to read and
> > process
> > an empty file?
> >
>
>
> A truly empty TEXT file will have no characters, and therefore zero bytes,
> no? That being the case, FileLen would appear to give you what you want: the
> size of the file in bytes, and if zero, an empty file.
>
> --
> Regards,
>
> Rick Raisley
> heavymetal-A-T-bellsouth-D-O-T-net
>
>
>
Author
1 Jun 2009 6:49 PM
David Kerber
In article <E5AB7610-62CF-4802-9B91-696AC8301***@microsoft.com>,
B**@discussions.microsoft.com says...
> FileLen is limited to Long, so will fail for large files.

Hopefully he's not d/l'ing files over 2GB.  What does FileLen() return
for files larger than that?  As long as it's not zero, he should be ok,
even if he needs to trap an exception.

.....

--
/~\ The ASCII
\ / Ribbon Campaign
X  Against HTML
/ \ Email!

Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Author
1 Jun 2009 7:33 PM
Rick Raisley
Right. A test on a 6 GB file gave a FileLen of 1873608704 (with no error),
and a FileLen of 1873608704 on a 207 GB file, so if the OP is just trying to
determine if a file is empty or not, that would certainly work. As the
FileLen given is some residual, and not the actual file size, it is possible
that every 2GB or so there is a precise file size that would fail and
evaluate to 0. But between the huge size, and the slim chances of that
happening, he can probably chance it. ;-)

--
Regards,

Rick Raisley
heavymetal-A-T-bellsouth-D-O-T-net

Show quoteHide quote
"David Kerber" <ns_dkerber@ns_WarrenRogersAssociates.com> wrote in message
news:MPG.248decd5324d6c3f989d19@news.conversent.net...
> In article <E5AB7610-62CF-4802-9B91-696AC8301***@microsoft.com>,
> B**@discussions.microsoft.com says...
>> FileLen is limited to Long, so will fail for large files.
>
> Hopefully he's not d/l'ing files over 2GB.  What does FileLen() return
> for files larger than that?  As long as it's not zero, he should be ok,
> even if he needs to trap an exception.
>
> ....
>
> --
> /~\ The ASCII
> \ / Ribbon Campaign
> X  Against HTML
> / \ Email!
>
> Remove the ns_ from if replying by e-mail (but keep posts in the
> newsgroups if possible).
>
Author
1 Jun 2009 6:51 PM
Rick Raisley
True, but a 2+ GB limit will read most/many files. Nothing was said by the
OP that these were huge data files.

--
Regards,

Rick Raisley
heavymetal-A-T-bellsouth-D-O-T-net

Show quoteHide quote
"Bee" <B**@discussions.microsoft.com> wrote in message
news:E5AB7610-62CF-4802-9B91-696AC8301945@microsoft.com...
> FileLen is limited to Long, so will fail for large files.
>
>
> "Rick Raisley" wrote:
>
>> "Rob" <R**@discussions.microsoft.com> wrote in message
>> news:02785FD4-D0CA-4074-81F5-2FC3BE8EFF23@microsoft.com...
>> >I have a VB6 program that I need to make modifications to so that it can
>> > determine the file size of a txt file that is downloaded to a folder
>> > (by a
>> > separate process).  This other process will put the file in this
>> > location
>> > whether or not it has any records in it.  Is there a way to
>> > programmitically
>> > determine if the file is empty, so as I can skip trying to read and
>> > process
>> > an empty file?
>> >
>>
>>
>> A truly empty TEXT file will have no characters, and therefore zero
>> bytes,
>> no? That being the case, FileLen would appear to give you what you want:
>> the
>> size of the file in bytes, and if zero, an empty file.
>>
>> --
>> Regards,
>>
>> Rick Raisley
>> heavymetal-A-T-bellsouth-D-O-T-net
>>
>>
>>
Author
3 Jun 2009 1:26 PM
Jeff Johnson
"Bee" <B**@discussions.microsoft.com> wrote in message
news:E5AB7610-62CF-4802-9B91-696AC8301945@microsoft.com...

> FileLen is limited to Long, so will fail for large files.

I think Randy's site has an API version which will handle > 2GB.
http://vbnet.mvps.org.