Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script works with const but not args

Status
Not open for further replies.

ixoni

MIS
May 12, 2003
9
0
0
IE
This simple script enumerates through all the subfolders under a given folder, and echos back the sizes of subfolders that are over a set minimum size. It works as it is posted here, only enter the path arg. But I want to enter both the path and the MinSize as args. But you can see I also have commented out code to use the Minsize from wscript.arguments instead of the Const = MinSize. When I do that, set the MinSize from the args, it does not work. It does not error, but it does not work either, it just runs and finishes without echoing anything. I cannot figure out the problem! I have used echo in the sub to debug and it does carry the arg variable MinSize all the way through. ??
Thanks, Barry

'BLH adapted from Windows 2000 scripting guide 12/22/03
'Check all subfolders below given folder for size over a minimum size.
Dim FolderPath
Dim FolderSize
'Dim MinSize 'uncomment to use args instead.
Const CONVERSION_FACTOR = 1048576 'converts folder size to MB
Const MinSize = 100 'set minimum folder size in MB.
If Wscript.Arguments.count = 0 Then
Wscript.Echo "Usage: foldersize.vbs [folder][minimum size]"
Wscript.Echo "Example: foldersize.vbs c:\myfolder 50"
Wscript.Quit
End If

FolderPath = Wscript.Arguments(0)
'MinSize = Wscript.Arguments(1)

Set FSO = CreateObject ("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder(FolderPath)

Sub ShowSubFolders (Folder)
For Each SubFolder In Folder.SubFolders
FolderSize = SubFolder.Size / CONVERSION_FACTOR
If FolderSize > MinSize Then
Wscript.Echo int(FolderSize) & vbTab & SubFolder.Path
End If
ShowSubFolders SubFolder
Next

End Sub
 
Have you tried this ?
Set objArgs=WScript.Arguments
FolderPath=objArgs(0)
MinSize=CLng(objArgs(1))

Hope This Help
PH.
 
Thats it! Thank you so much. Obviously, I have a lot to learn yet.

-Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top