Thursday, July 12, 2012

To take folder size from vb script (cscript sourcefile.vbs)

Dim objShell  'holds WshShell object   
Dim objExecObject  'holds what comes back from executing the command
Dim strText  'holds the text stream from the exec command.
Dim command  'the command to run
Dim Directory  'directory to query

Directory = Wscript.Arguments(0)

command = "cmd /c dir " & Directory & " /s"

'WScript.echo command
'WScript.echo "starting program " & Now ' used to mark when program begins

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec(command)


Do Until objExecObject.StdOut.AtEndOfStream

   strText = objExecObject.StdOut.ReadAll

Loop

aryText = Split(strText, VbNewLine)

'wscript.Echo "There are " & ubound(aryText) & " items in the " & Directory & " Folder"
Wscript.Stdout.Write Directory
Wscript.Stdout.Write aryText(ubound(aryText) -2)
'Wscript.Stdout.Write aryText(ubound(aryText) -1)

for example :

cscript size.vbs \\server100\newfolder\user1 //NoLogo >> sourcesize.txt

No comments:

Post a Comment