BUG: File System Object Size Method Fails on Root Folder on Windows 95, Windows 98, and Windows Millennium Edition (322717)
The information in this article applies to:
- Microsoft JScript 3.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft JScript 4.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft JScript 5.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft JScript 5.5, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic, Scripting Edition 3.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic, Scripting Edition 4.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic, Scripting Edition 5.0, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic, Scripting Edition 5.5, when used with:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
This article was previously published under Q322717 SYMPTOMS
If you use the File System Object to determine the size of a folder, you receive the following error message when you call the Size method for a root folder ("C:") on a computer that is running Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows Millennium Edition (Me):
Runtime Error 76
Path Not Found
The code that causes this error appears similar to the following code:
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim f As Folder
Set f = fso.GetFolder("C:\")
Dim amnt As Double
' This line fails with the error.
amnt = f.Size
This same code works as expected on a computer that is running Microsoft Windows NT, Microsoft Windows 2000, or Microsoft Windows XP.
CAUSE
When you use the name of the folder (the FolderPath property) in the code for the Size function of the File System Object, the root folder has a trailing slash, and all of the other folders do not have a trailing slash. This causes logic such as "FolderPath\*" to fail on the root folder because the resulting string is "C:\\*". A string such as this should return all of the files and the folders in that folder. However, this string fails on a computer that is running Windows 95, Windows 98, or Windows Millennium Edition with the error message that is listed in the "Symptoms" section of this article. Windows NT, Windows 2000, and Windows XP just ignore the double slash and return the correct list of files and folders.
The code in the Size method should remove the slash from the FolderPath for the root folder before it performs operations.
RESOLUTION
To work around this problem, provide a custom Size method that handles the root folder. For example, use the following code instead of Folder.Size:
Function Size ( f As Folder ) As Double
Dim amnt As Double
If f.IsRootFolder = False Then
amnt = f.Size
Else
Dim myFile As File
For Each myFile In f.Files
amnt = amnt + myFile.Size
Next
Dim myFolder As Folder
For Each myFolder In f.SubFolders
amnt = amnt + myFolder.Size
Next
amnt = amnt
End If
Size = amnt
End Function
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 12/12/2003 |
---|
Keywords: | kbbug kbpending KB322717 kbAudDeveloper |
---|
|