Having failed to make it work in WSH I turned my attention to .Net scripting
First, PowerShell
OK technically this is not a script but what I actually typed at the command line to get a list of all folders consuming more than 40MB. Because I used the $pwd variable I can just CD into the desired root folder and up arrow and re-use the same 'code'. PERL coders may recognise the use of $_ to represent the current record. The % is an alias for the ForEach-Object enumerator.Code:PS_Prompt> $fso= New-Object -ComObject Scripting.FilesSystemObject PS_Prompt> CD E:\HomeFolders\Year7 PS_Prompt> $hmrt = $fso.GetFolder($pwd) ; $hmrt.subfolders| where-object -filterscript {$_.size -gt 40000000} | % {write-host $_.Name,($_.size/1024/1024) -Separator ","}
I also tried using the .NET version of JScript
This is more compiled rather interpreted 'scripting'
This compiles to an EXE using jsc and will tell you the number of megabytes consumed by the subfolders in the current directory.Code:var fso = new ActiveXObject("Scripting.FileSystemObject"); var f = fso.GetFolder(".\\"); var fc = new Enumerator(f.SubFolders) ; for (;!fc.atEnd(); fc.moveNext()) { print(fc.item().path + " " + (fc.item().size/1024/1024)); };
Notice print() ather than wscript.echo(). This is .net not WSH so you loose alot of the properties and methods of the wscript object, which is quite annoying.
Anyway, it is clear that there wasn't a permissions issue as the relevant FSO methods work under .NET but not WSH
Go figure </American



LinkBack URL
About LinkBacks
Reply With Quote

