Results 1 to 6 of 6

Thread: Get file size

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258

    Get file size

    How do I get the size of a file?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    VB Code:
    1. Imports System
    2. Imports System.IO
    3. Public Module modmain
    4.    Sub Main()
    5.       'KPD-Team 2001
    6.       'URL: [url]http://www.allapi.net/dotnet/[/url]
    7.       'E-Mail: [email][email protected][/email]
    8.       Dim MyFile as new FileInfo ("c:\autoexec.bat")
    9.       Console.WriteLine("The length of autoexec.bat is " _
    10.          + MyFile.Length.ToString + " bytes.")
    11.    End Sub
    12. End Module
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258
    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:
    1. Private Sub SearchDir(ByVal TargetDir As String)
    2.         Dim Files() As String
    3.         Dim File As String
    4.         Dim Dirs() As String
    5.         Dim Dir As String
    6.         Dim FileInfo As IO.FileInfo
    7.         Dim DirInfo As IO.DirectoryInfo
    8.  
    9.  
    10.         Dirs = IO.Directory.GetDirectories(TargetDir)
    11.         lstDirs.Items.Clear()
    12.         lstDirs.Items.Add("UP")
    13.         For Each Dir In Dirs
    14.             lstDirs.Items.Add(Dir)
    15.         Next
    16.  
    17.         Files = IO.Directory.GetFiles(TargetDir, "*.*")
    18.         lsvFiles.Items.Clear()
    19.         For Each File In Files
    20.             'add item to list view box
    21.             lsvFiles.Items.Add(File)
    22.             FileInfo = New IO.FileInfo(File)
    23.             lsvFiles.Items(lsvFiles.Items.Count - 1).SubItems.Add(FileInfo.Length)
    24.         Next
    25.  
    26.         'store parent directory
    27.         DirInfo = New IO.DirectoryInfo(TargetDir)
    28.         UpDir = DirInfo.Parent.ToString     'causes error
    29.     End Sub


    Also, how do you change the mouse cursor? In VB6...twas
    VB Code:
    1. me.mousepointer = vbhourglass
    2. me.mousepointer = vbDefault

    ??????
    ?????
    ????

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
    umm and what's the error anyways?


    HTH
    Last edited by MrPolite; Sep 23rd, 2002 at 01:32 AM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258
    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:
    1. dim DirInfo as IO.DirectoryInfo
    2.  
    3. 'later in sub (in a loop)
    4. DirInfo = New IO.DirectoryInfo(TargetDir)
    5. 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?

  6. #6

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258
    Got it from another post

    Mystring.Substring()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width