Link to home
Start Free TrialLog in
Avatar of billyboy71
billyboy71

asked on

getting filenames and filesize of files through vb.net 2005

Hi,

I have the following vb.net  2005 script for listing files in a directory.

 Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        files1 = System.IO.Directory.GetFiles(txtDirectory.Text)
        Dim sw As New System.IO.StreamWriter(txtFileName.Text)
        sw.Write(String.Join(ControlChars.CrLf, files1))
    End Sub

It works find , but how to modify it so that I can get the file size to appear next to the filename on the output like the following:
c:\sometext.txt 16
c:\othertext.txt 45

I think a "tab" between the filename and the filesize would be ok.

Thanks.

Peter


Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Dim fileSize As Long = New FileInfo(path).Length

Bob
Use System.IO.FileInfo and the Length propertie to get the file size
FileInfo finfo = new FileInfo("fileName");
            fileSize = finfo.Length ;
            fileName = finfo.Name
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

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