Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting the number of files in a subfolder

    here's my script so far, but I can't seem to get the number of files of the subfolder into the array I set up

    <%
    dim dirinfo(10,2)
    dirs = 0
    ShowSub = request("ShowSub")
    ShowPic = request("ShowPic")
    strPathInfo = Request.ServerVariables("PATH_INFO")
    strPhysicalPath = Server.MapPath(strPathInfo)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strPhysicalPath)
    Set objFolder = objFile.ParentFolder
    Set objFolderContents = objFolder.Files
    For each Folder in objFolder.SubFolders

    dirinfo(dirs,1) = Folder.Name
    dirinfo(dirs,2) = objFolder.SubFolders.Files.count
    dirs = dirs + 1
    Next
    dirs = dirs - 1
    Set objFSO = Nothing
    %>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Did you get a subscript out of range error?
    VBScript arrays are zero-based like many other languages.

    dirinfo(dirs, 0) = Folder.Name
    dirinfo(dirs, 1) = objFolder.SubFolders.Files.count

    You started the first dimension (dirs) at zero. I wonder why you started the second dimension to 1.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Registered User
    Join Date
    Jan 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, I didn't even see that, but this is the error that I get:

    Object doesn't support this property or method: 'objFolder.SubFolders.Files'
    /photos/index.asp, line 17



    I'm not even sure the code I used it possible, it's just the one I thought was the most logical.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    dim objFiles
    For each Folder in objFolder.SubFolders
      dirinfo(dirs, 0) = Folder.Name
      set objFiles = Folder.Files
      dirinfo(dirs, 1) = objFiles.count
      dirs = dirs + 1
    Next
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Registered User
    Join Date
    Jan 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect! worked great!

    One more question...

    right now I have the array just defined as

    dim dirinfo(10,2)

    but if there are more then 10 directories it won't work. How would I set it up so that it is a dynamic array?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Use ReDim
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •