Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Double error in For Each loop

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60615
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Double error in For Each loop
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Double error in For Each loop - 5/23/2008 2:25:40 AM   
  TomGuy

 

Posts: 7
Score: 0
Joined: 5/23/2008
Status: offline
Hi All,
 
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:

C:
|__Temp
    |__Folder1
    |   |__XPprofile
    |__Folder2
    |   |__Folder2a
    |__Folder3
    |   |__Folder3a
    |__Folder4  <----------Deny access to this
    |__Folder5
    |   |__Folder5a
    |__Folder6
        |__XPprofile

(To deny yourself access, go to the security tab of the folder, select your username and enable the checkbox under deny for Full Control.)

And here's the code:


      
 
 
Post #: 1
 
 RE: Double error in For Each loop - 5/23/2008 7:22:48 AM   
  Thenewguy

 

Posts: 3
Score: 0
Joined: 8/10/2005
Status: offline
This is working for me when i try it..

'--- begin script

Dim objFSO, strStartFolder, objStartFolder


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
  
End Sub

msgbox "Done!"

'--- end script

(in reply to TomGuy)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Double error in For Each loop Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts