Link to home
Start Free TrialLog in
Avatar of kamleshmistry
kamleshmistry

asked on

how to i get the size in bytes of a file in vb.net


how do i get the size of a file?

system.file.io.files.getattributes("path").size? ... no, that's not right....


Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiofileinfoclasslengthtopic.asp

from MSDN:

' The following example displays the names and sizes
' of the files in the specified directory.
Imports System
Imports System.IO

Public Class FileLength

    Public Shared Sub Main()
        ' Make a reference to a directory.
        Dim di As New DirectoryInfo("c:\")
        ' Get a reference to each file in that directory.
        Dim fiArr As FileInfo() = di.GetFiles()
        ' Display the names and sizes of the files.
        Dim f As FileInfo
        Console.WriteLine("The directory {0} contains the following files:", di.Name)
        For Each f In fiArr
            Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length)
        Next f
    End Sub 'Main
End Class 'FileLength
Avatar of kamleshmistry
kamleshmistry

ASKER



not bad, but how do I get the size of a particular file, provided I know the path

Input:  file path

Output:  file size...
ASKER CERTIFIED SOLUTION
Avatar of GrumbleBot
GrumbleBot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that is correct.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
timbo why open the file when you dont have to ?
If you're using a method that takes in a Stream, it will provide the stream and the file size. Considering he has one specific file, I have a feeling he's going to open it anyways.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial