How do I get the size of a file?
Printable View
How do I get the size of a file?
VB Code:
Imports System Imports System.IO Public Module modmain Sub Main() 'KPD-Team 2001 'URL: [url]http://www.allapi.net/dotnet/[/url] 'E-Mail: [email][email protected][/email] Dim MyFile as new FileInfo ("c:\autoexec.bat") Console.WriteLine("The length of autoexec.bat is " _ + MyFile.Length.ToString + " bytes.") End Sub End Module
Hey thanks for the quick reply. If you could answer a few more noob questions, you will help me on my way.
I tried to use the same technique to get a dirs parent dir....but no luck
VB Code:
Private Sub SearchDir(ByVal TargetDir As String) Dim Files() As String Dim File As String Dim Dirs() As String Dim Dir As String Dim FileInfo As IO.FileInfo Dim DirInfo As IO.DirectoryInfo Dirs = IO.Directory.GetDirectories(TargetDir) lstDirs.Items.Clear() lstDirs.Items.Add("UP") For Each Dir In Dirs lstDirs.Items.Add(Dir) Next Files = IO.Directory.GetFiles(TargetDir, "*.*") lsvFiles.Items.Clear() For Each File In Files 'add item to list view box lsvFiles.Items.Add(File) FileInfo = New IO.FileInfo(File) lsvFiles.Items(lsvFiles.Items.Count - 1).SubItems.Add(FileInfo.Length) Next 'store parent directory DirInfo = New IO.DirectoryInfo(TargetDir) UpDir = DirInfo.Parent.ToString 'causes error End Sub
Also, how do you change the mouse cursor? In VB6...twas
VB Code:
me.mousepointer = vbhourglass me.mousepointer = vbDefault
??????
?????
????
umm for the cursor:
Me.Cursor = Cursors.WaitCursor
to get a direcotory's parent DIR, I tried this, dunno if it's what you're looking for:
System.IO.Directory.GetParent("C:\windows\system").FullName()
btw I tried your code like this:
Dim dirInfo As New IO.DirectoryInfo("c:\windows\system")
MsgBox(dirInfo.Parent.ToString)
it works, maybe you are passing something weirdo to the function, I didnt really read you code:D
umm and what's the error anyways? :rolleyes:
HTH:)
Thanks Mr.Polite. You have been a great help.
The cursor code worked great. Here is what I ended up using for the DirInfo
VB Code:
dim DirInfo as IO.DirectoryInfo 'later in sub (in a loop) DirInfo = New IO.DirectoryInfo(TargetDir) UpDir = DirInfo.Parent.FullName
The problem was that I was passing the root of the drive as the TargetDir and that was causing an error. I just needed some error handling.
More questions......
How do you do the Right, Left, and Mid string functions in VB.net?
Got it from another post
Mystring.Substring()