|
-
Oct 13th, 2000, 08:40 AM
#1
Thread Starter
Hyperactive Member
What would be quickest way?
-RaY
VB .Net 2010 (Ultimate)
-
Oct 13th, 2000, 08:53 AM
#2
Fanatic Member
Probably the GetFileSize API would be fastest. http://www.vbapi.com/ref/g/getfilesize.html
Or you could check the LOF of the file, but that would require opening the file in VB.
Code:
Private Sub Command1_Click()
Dim strFileName As String
Dim intFileNum As Integer
intFileNum = FreeFile
strFileName = "c:\query.log"
Open strFileName For Input As #intFileNum
If LOF(intFileNum) = 0 Then
MsgBox "File is empty"
End If
Close #intFileNum
End Sub
[Edited by jbart on 10-13-2000 at 09:55 AM]
-
Oct 13th, 2000, 09:02 AM
#3
I assume that on each OS you will have the same (albeit slightly different from other OS's) file size for the same number of characters.
If you are using only one OS, simply find the filesize for an empty file and compare it to the current file size of the target file.
Alternatively, you could write a dummy blank file, get THAT file size and compare it to the filesize of the target file.
I don't know, however, that that would be faster (in real time) than just opening up the file and attempting to read the first characters.
Good Luck
DerFarm
Well, I see that Jbart beat me to it, and his answer is better anyway......
-
Oct 13th, 2000, 09:06 AM
#4
Frenzied Member
Or use
Code:
Private Function IsEmpty(File As String) As Boolean
If FileLen(File) = 0 Then
IsEmpty = True
Else
IsEmpty = False
End If
End Function
'USAGE:
'MsgBox IsEmpty("C:\myfile.txt")
I think it's a bit slower than the api, but it makes no noticable difference I think!
[Edited by Jop on 10-13-2000 at 10:08 AM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 13th, 2000, 09:08 AM
#5
Fanatic Member
Thanks Jop. I never used FileLen before. Looks like that would be the quickest and easiest way, since you do not need to open the file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|