From: Prometheus_Fire on
Hi All, I'm trying to create a simple script that will return a list of
folders in the current directory and their respective sizes:

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set strCurrentDirectory = objFSO.GetParentFolderName(Wscript.ScriptFullName)

Set objFolder = objFSO.GetFolder("strCurrentDirectory")
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next

Yet it doesn't like the fact that I am trying to pass the current directory
into a variable and errors out with: D:\dirsize.vbs(3, 1) Erreur d'exécution
Microsoft VBScript: Objet requis: '[string: "D:\"]'. Can anyone point me in
the right direction please?
--
Knowledge is realising that the street is one-way.

Wisdom is looking both directions anyway!
From: Mayayana on
Remove the quotes in the call to GetFolder.
You've turned a variable into a string, and
the string "strCurrentDirectory" is not a valid
path.

Also: Your current code can only go down 1 level.
If you want a full list you need to use a global variable
to hold the list and then put the listing operation
inside a recursive function.


|
| Set objShell = CreateObject("WScript.Shell")
| Set objFSO = CreateObject("Scripting.FileSystemObject")
| Set strCurrentDirectory =
objFSO.GetParentFolderName(Wscript.ScriptFullName)
|
| Set objFolder = objFSO.GetFolder("strCurrentDirectory")
| Set colSubfolders = objFolder.Subfolders
|
| For Each objSubfolder in colSubfolders
| Wscript.Echo objSubfolder.Name, objSubfolder.Size
| Next
|
| Yet it doesn't like the fact that I am trying to pass the current
directory
| into a variable and errors out with: D:\dirsize.vbs(3, 1) Erreur
d'ex�cution
| Microsoft VBScript: Objet requis: '[string: "D:\"]'. Can anyone point me
in
| the right direction please?
| --
| Knowledge is realising that the street is one-way.
|
| Wisdom is looking both directions anyway!