tinomesa Posted August 12, 2003 Posted August 12, 2003 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 Quote
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 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. Quote
tinomesa Posted August 12, 2003 Author Posted August 12, 2003 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 Quote
Administrators PlausiblyDamp Posted August 12, 2003 Administrators Posted August 12, 2003 if you bring up the property page in explorer for one of these 1k but empty files what does it say about the file size there? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 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. Quote
tinomesa Posted August 12, 2003 Author Posted August 12, 2003 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? Quote
tinomesa Posted August 12, 2003 Author Posted August 12, 2003 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!!! Quote
Administrators PlausiblyDamp Posted August 13, 2003 Administrators Posted August 13, 2003 Explorer has a tendancy to round numbers up to the nearest 1K or 1M depending on size. The two bytes are probably a CRLF or something similar. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.