I've got an error that's really starting to tick me off!!! I'm hoping you'll be able to help me out...
The following code is supposed to read through 2 layers of subfolders and determine if a folder named XPprofile exists. Also, if access is denied to a folder due to permission issues, it’s supposed to display a msgbox saying so. The problem is that when it encounters such an error it displays the msgbox for both the folder where access is denied as well as the following folder (where access is Not denied). To recreate my error, create the following structure below c:\temp:
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOutputFile = objFSO.CreateTextFile("c:\temp\Output.txt") strStartFolder = "c:\temp" Set objStartFolder = objFSO.GetFolder(strStartFolder)
Call ShowSubFolders(objStartFolder)
Sub ShowSubFolders(Folder)
on error resume next
For Each Subfolder in Folder.SubFolders blnFound = False
For Each SubSubFolder in Subfolder.Subfolders if err.number = 70 then ' 70 means an access denied error msgbox "Access is denied to the folder:" & Subfolder, vbExclamation, "Error" end if if lcase(SubSubfolder.name) = "xpprofile" then blnFound = True end if err.clear ' this should be clearing the error to 0...which is does but then it's set back to 70 for the next folder even though access is NOT denied on the next folder...Aaaggghhh!! Next
if blnFound = False then objOutputFile.WriteLine(subfolder.name) end if Next