Board index » Visual Studio » Foldersize

Foldersize

Visual Studio78
Hi all,



how can I determine the foldersize using WMI

Perhaps someone has written such a script before that does this job and

knows what is wrong.



Thanks in advance

Helmut



Here is a code excerpt:



server = "myServer"



Set wmi = GetObject("winmgmts://" & server & "/root/cimv2")



Set basis = wmi.get("Win32_Directory.name='s:\myfolder'")



MsgBox basis.GetObjectText_ ' o.k.



Set klassen = basis.Associators_ (, "Win32_LogicalDisk", , , , , , , 32)



For Each klasse In klassen



list = list & klasse.size Next



MsgBox list


-
 

Re:Foldersize

Hi Helmut! :)



First of all, break the row "list = list & klasse.size Next" into two rows

like this:

list = list & klasse.size

Next



But what are you trying to find out? If you take size from Win32_LogicalDisk

you get the size of the disc. Is this what you wanted or do you want the

size of the folder?



http://msdn.microsoft.com/library/default.asp?url" rel="nofollow" target="_blank">msdn.microsoft.com/library/default.asp=/library/en-us/wmisdk/wmi/win32_directory.asp

http://msdn.microsoft.com/library/default.asp?url" rel="nofollow" target="_blank">msdn.microsoft.com/library/default.asp=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp





The easiest way to get the size of a folder is to use the filesystem object:

strPath = "\\server.domain.com\directory"

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFileSystem.GetFolder(strPath)

WScript.Echo("Folder size: "+CStr(objFolder.Size))



As you see it works well with UNC paths as well. Be aware that the Size()

function fails and you get an error if you don't have full permissions on

all subfolders and files in the directory.



Hope this helps! :)



/Sofia





"Helmut Driessen" <helle@ukaachen.de>wrote in message

Quote
Hi all,



how can I determine the foldersize using WMI

Perhaps someone has written such a script before that does this job and

knows what is wrong.



Thanks in advance

Helmut



Here is a code excerpt:



server = "myServer"



Set wmi = GetObject("winmgmts://" & server & "/root/cimv2")



Set basis = wmi.get("Win32_Directory.name='s:\myfolder'")



MsgBox basis.GetObjectText_ ' o.k.



Set klassen = basis.Associators_ (, "Win32_LogicalDisk", , , , , , , 32)



For Each klasse In klassen



list = list & klasse.size Next



MsgBox list









-

Re:Foldersize

Like Sofia said, Use FileSystem object instead. WMI does not allow you to do

so...



www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1118.mspx">www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1118.mspx



Ramon



"Helmut Driessen" <helle@ukaachen.de>wrote in message

Quote
Hi all,



how can I determine the foldersize using WMI

Perhaps someone has written such a script before that does this job and

knows what is wrong.



Thanks in advance

Helmut



Here is a code excerpt:



server = "myServer"



Set wmi = GetObject("winmgmts://" & server & "/root/cimv2")



Set basis = wmi.get("Win32_Directory.name='s:\myfolder'")



MsgBox basis.GetObjectText_ ' o.k.



Set klassen = basis.Associators_ (, "Win32_LogicalDisk", , , , , , , 32)



For Each klasse In klassen



list = list & klasse.size Next



MsgBox list









-