For Each Loop not working.

Author Message
Yzerman19

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 12/18/2011
  • Status: offline
For Each Loop not working. Sunday, December 18, 2011 4:55 PM (permalink)
0
First post here. I'm trying to loop through a folder to get the files within, but for some odd reason the For Each loop only goes through once, here's my code:
 
Dim k
 k = 0 
 For Each pdf2 In pdfDir.Files
 k = k+1
 Next
 
 Wscript.echo k
 Wscript.Quit

 
The output of the echo is always 1, but I have 3 files within the pdfDir directory, what's the problem?
This VBScript is within a wsf file, I'm not sure if this makes a difference or not but it's really frustrating that the For Each loop is not working (Other loops do work).
 
#1
    thenson81

    • Total Posts : 8
    • Scores: 0
    • Reward points : 0
    • Joined: 12/18/2011
    • Status: offline
    Re:For Each Loop not working. Sunday, December 18, 2011 5:00 PM (permalink)
    0
    pretty sure all my file work was done more by using
     
    set files = pdfDir.files
     
    for each pdf2 in files
    k = k + 1
    next
     
     
    not sure if it matters doing it this way but all my for each work fine
     
    #2
      Yzerman19

      • Total Posts : 5
      • Scores: 0
      • Reward points : 0
      • Joined: 12/18/2011
      • Status: offline
      Re:For Each Loop not working. Sunday, December 18, 2011 5:03 PM (permalink)
      0
      Thanks for the reply. I tried it that way too, no luck. It only loops once.
       
      This does not make sense at all.
       
      #3
        Yzerman19

        • Total Posts : 5
        • Scores: 0
        • Reward points : 0
        • Joined: 12/18/2011
        • Status: offline
        Re:For Each Loop not working. Sunday, December 18, 2011 5:34 PM (permalink)
        0
        Ok, as I debug, pdfDir.Files returns empty, why would it return empty when there are 3 files in the folder?
         
        #4
          Yzerman19

          • Total Posts : 5
          • Scores: 0
          • Reward points : 0
          • Joined: 12/18/2011
          • Status: offline
          Re:For Each Loop not working. Sunday, December 18, 2011 5:47 PM (permalink)
          0
          Nm, I solved it :)
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • 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
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9