Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test if a textfile is empty ?

Status
Not open for further replies.

eurob

Programmer
Jan 25, 2004
13
US
I'd like to know if it possible to test a text file for empty. I use this:

set I'd like to know if it possible to test a text file for empty. I use this:

set textcontent = fsoObject.OpenTextFile(textfile , 1)
strBuffer = textcontent.ReadAll

which works fine if the textfile contains characters, but when the file is empty I get
Microsoft VBScript
runtime (0x800A003E)
Input past end of file, because the file is empty.

Appreciate your help,

Robert
 
i found it,

if not textcontent.atendofstream then
strBuffer.readall
end if
 
Or more generically you could use:

if fsoObject.FileExists(textfile) then
if fsoObject.GetFile(textfile).size <> 0 then
' open the file and process it
end if
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top