Calculate the File Size on disk in KB RRS feed

  • Question


    hey,Frnds I Have tried the Fill. Code,But the Foll. Code returns the no. of charcters of the File,But i want the File Size on Disk in KB.
     Can u Plz help me out.
    Imports System
    Imports System.IO

    Dim filelength As Long = 0

     Dim objfile As New FileInfo("D:\Documents and Settings\Administrator\Desktop\URLs[1].txt")

     filelength = filelength + file.Length

    Saturday, June 21, 2008 5:23 PM


  • That code returns the file size in bytes on disk, but perhaps you mean actually allocated space on disk, which means the number and total size of clusters used to hold the file? If so you need to find some code to get the size of a cluster on disk and then round up the number of bytes to the nearest whole cluster.

    Besides, your code seems odd, you declare a variable called objFile, but then read file.Length, are you sure you are reading the right variable?

    I would find it very very odd if any code actually measured the number of *characters* a file contains, since that will vary depending on the encoding the file uses, so I'm guessing you're confusing this with actually allocated space for the file.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bruno Yu Thursday, June 26, 2008 1:55 AM
    Saturday, June 21, 2008 7:05 PM