|
-
Apr 4th, 2006, 01:07 PM
#1
Thread Starter
New Member
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?
-
Apr 9th, 2006, 05:44 AM
#2
Frenzied Member
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
-
Apr 10th, 2006, 09:05 AM
#3
Thread Starter
New Member
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:
Option Explicit
Dim oShell, oFSO
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim sFile, sTempFile, aText, i, aInfo
sFile = "C:\myCompressedFile.doc"
sTempFile = oFSO.GetAbsolutePathName("monfichiertemp.tmp")
oShell.Run "%comspec% /c compact " & Chr(34) & sFile & Chr(34) & " > " & Chr(34) & sTempFile & Chr(34), 0, True
aText = Split(oFSO.OpenTextFile(sTempFile,1).ReadAll,VbCrLf)
aInfo = Split(Replace(aText(4),"=",":"), ":")
WScript.Echo sFile & " : Size = " & Trim(aInfo(0))
WScript.Echo sFile & " : Size on Disk = " & Trim(aInfo(1))
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
-
Apr 10th, 2006, 01:00 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|