Results 1 to 4 of 4

Thread: File's Size On Disk

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    File's Size On Disk

    Hello,

    I'm scanning files on a server and getting all their attributes (size, folder, owner, last accessed ...etc) and putting those in a Database, all this in a *.vbs file.
    I'm use the following objects: "Scripting.FileSystemObject" and "Shell.Application"
    They have all the functions I need, except the one wich would give me the "Size On Disk".
    Fact is that the server i'm scanning uses compression (ntfs compressed drive) so the "Size on Disk" is way smaller than the size...
    ex, for a *.xls file:
    size: 994 KB
    size on disk: 420 KB

    is there any way I could get this information with vbscript?

  2. #2
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: File's Size On Disk

    jetana:

    In addition to the FileSystemObject the Scripting Runtime Library has an object called the File Object. The File Object has a "size" property that returns the size of the file in bytes. However, since compression is being used you most likely will get the compressed size rather than the uncompressed size.

    I'm not sure if this solves your problem or not.

    Good Luck

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: File's Size On Disk

    In addition to the FileSystemObject the Scripting Runtime Library has an object called the File Object
    Unfortunately, the File Object is the one I'm using to get the file's size and it is returning the "size" attribute, not the compressed "size on disk". By the way, the Size object is only a class that belongs to the FileSystemObject Library, and it's the only one that gives you the size attribute.
    But someone else gave me a solution that worked! it's a little tricky and it might be a little slow if you're scanning a big number of files but it's working.
    It uses the dos command COMPACT.EXE to get the file size and size on disk of a compressed file. It writes the result of the command in a temporary text file, and then reads the "size" and "size on disk" values to finally display them in a message box:

    VB Code:
    1. Option Explicit
    2. Dim oShell, oFSO
    3. Set oShell = CreateObject("Wscript.Shell")
    4. Set oFSO = CreateObject("Scripting.FileSystemObject")
    5. Dim sFile, sTempFile, aText, i, aInfo
    6. sFile = "C:\myCompressedFile.doc"
    7. sTempFile = oFSO.GetAbsolutePathName("monfichiertemp.tmp")
    8. oShell.Run "%comspec% /c compact " & Chr(34) & sFile & Chr(34) & " > " & Chr(34) & sTempFile & Chr(34), 0, True
    9. aText = Split(oFSO.OpenTextFile(sTempFile,1).ReadAll,VbCrLf)
    10. aInfo = Split(Replace(aText(4),"=",":"), ":")
    11. WScript.Echo sFile & " : Size = " & Trim(aInfo(0))
    12. WScript.Echo sFile & " : Size on Disk = " & Trim(aInfo(1))
    13. If oFSO.FileExists(sTempFile) Then oFSO.DeleteFile sTempFile, True
    Be Aware that this code doesn't consider the bytes that are lost because of the size of the clusters on your disk... it only shows a difference if there's an ntfs compression.
    Thanks to DiGiTAL.SkReAM and www.visualbasicscript.com

  4. #4
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: File's Size On Disk

    jetana:

    Thank You for posting the solution.

    I am glad your problem got resolved.

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