2

I am writing a script to determine the combined size of all instances of a particular subfolder within the profile folder of each user who has logged onto a Windows 2003 server, e.g. all users' desktop folders or all users' local settings folders.

Option Explicit
Dim colSubfolders, intCount, intCombinedSize, objFolder2, objFSO1, objFSO2, objUserFolder, strOutput, objSearchFolder, objSubfolder, strSearchFolder, strSubfolderPath

intCount = 0
intCombinedSize = 0
strSearchFolder = "C:\Documents and Settings\"

Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objSearchFolder = objFSO1.GetFolder(strSearchFolder)
Set colSubfolders = objSearchFolder.SubFolders

For Each objUserFolder in colSubfolders
  strSubfolderPath = objUserFolder.Path & "\Desktop\"
  Set objFSO2 = CreateObject("Scripting.FileSystemObject")
  Set objSubfolder = objFSO2.GetFolder(strSubfolderPath)
  intCount = intCount + 1
  intCombinedSize = intCombinedSize + objSubfolder.Size
Next

MsgBox "Combined size of " & CStr(intCount) & " folders: " & CStr(intCombinedSize / 1048576) & " MB"

This code throws a 'Path not found' error (Code 800A004C) at line 15:

Set objSubfolder = objFSO2.GetFolder(strSubfolderPath)

If I print out strSubfolderPath, however, I find that all the strings returned are valid directory paths, so I don't understand why I'm getting this error.

I've tried with and without the trailing backslash at the end of the path and I've tried with 8.3 style paths to remove spaces but to no effect.

4
  • Does the account you run the script under has permissions to access these folders and view their size in Windows Explorer? Commented Aug 30, 2011 at 12:15
  • 1
    Curious: why are you creating more than one FileSystemObject instead of just reusing the same one? Commented Aug 30, 2011 at 13:24
  • Didn't realise I didn't need to create another FileSystemObject as I'm still new to VBS. Thanks @Jean-François Corbett for pointing that out. Commented Aug 30, 2011 at 14:01
  • 1
    @Helen I forgot to include in the original question that the script is running as an administrator account with access to all the directories, but thanks for checking. Question solved now. Commented Aug 30, 2011 at 14:05

2 Answers 2

1

When I run your code I get the same error.

Upon further inspection, on my computer there is a folder named C:\Documents and Settings\machinename, where machinename is the name of my computer. This folder only contains one subfolder named ASPNet.

I'm guessing you have something similar.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks. I hadn't spotted the hidden folders LocalService and NetworkService, which are Desktop-less. I added If objFSO.FolderExists(strSubfolderPath) Then and it worked fine.
1

To minimize multiple-backslash confusion, use the FileSystemObject methods consistently instead of relying on string concatenation:

strSubfolderPath = objFSO1.BuildPath(objUserFolder.Path,"Desktop")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.