Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Greetings,

 

 

I have a program that iterates through a series of text files and if the file size is 0 it writes to the file.

 

The problem is that I have text files that are empty but show up as being 1kb in size.....

 

Is there a way to find out if the file is empty preferably without the expense of "reading it" ?

 

Thanks,:D

  • *Experts*
Posted

You can use the Length property of FileInfo class:

Dim fi as new IO.FileInfo("path to the file")
MessageBox.Show(fi.Length.ToString())

If there is no text in the file the Length will be 0.

Posted

Thanks for the response Mutant,

 

But as I said above the file size is being reported as 1kb.

 

I think I am going to have to read a portion of the file an make a determination on wheater is null or not.......

 

Maybe one of you experts can tell me how "peek" works... and what it returns if there is nothing there to peek at.

 

Thanks

  • *Experts*
Posted
What I showed you shouldnt report 1kb on a empty file, it returns the numbers of bytes in the files, how many characters. If the file is empty then it will return 0.
Posted

Thanks for participating PlausiblyDamp,

 

the size is consistent at 2 Bytes,

 

It would work to check for size <= 2.......but how does the system diferenciate between 2kb and 2bytes.....

 

2KB maybe a correct file (not empty) that I do not want to overwrite.

 

any ideas?

Posted

mutant

 

How could I have doubted you..... Shame on me!!!

 

The length actually returns the number of bytes so you are

 

correct!!!

 

Seriously thanks to all for the help!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...