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.GetFil es(txtDire ctory.Text )
Dim sw As New System.IO.StreamWriter(txt FileName.T ext)
sw.Write(String.Join(Contr olChars.Cr Lf, 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
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.GetFil
Dim sw As New System.IO.StreamWriter(txt
sw.Write(String.Join(Contr
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
Use System.IO.FileInfo and the Length propertie to get the file size
FileInfo finfo = new FileInfo("fileName");
fileSize = finfo.Length ;
fileName = finfo.Name
fileSize = finfo.Length ;
fileName = finfo.Name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob