Collections in ASP: Names vs. Numbers

Discussion in 'ASP General' started by Nathan Sokalski, Jul 23, 2003.

  1. I am using the Folder.Files collection to display all the images in a given
    directory. The following shows the code I use to create and use this
    collection:

    Set myfilesys=Server.CreateObject("Scripting.FileSystemObject")
    Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))

    When I use a specific file name to access a file, my code works fine:

    <img src=" & Chr(34) & mydirectory.Name & "/" &
    mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">

    However, I want to iterate through all the files in the Folder USING NUMBERS
    (I already know how to do it using a For Each statement). But whenever I try
    to do this, I receive an error:

    <img src=" & Chr(34) & mydirectory.Name & "/" & mydirectory.Files(5).Name
    & Chr(34) & ">

    Other collections, such as the Request.Form collection allow you to access
    the collection using either text or numbers, and all books that I have read
    have said that this is true for all collections. Is the Folder.Files
    collection an exception to this? Is there something else I need to do? If
    anybody can give me any help on this, I would appreciate it. Thank You.
    --
    Nathan Sokalski

    http://www.students.kutztown.edu/soka0908/HomePage.html
     
    Nathan Sokalski, Jul 23, 2003
    #1
    1. Advertising

  2. Nathan Sokalski

    Ray at Guest

    The files collection doesn't support referencing an item by its index. Why?
    There's probably a reason. But you can only reference it by its key, which
    is the file name. Mind if I ask why you want to do this?

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Nathan Sokalski" <> wrote in message
    news:...
    > I am using the Folder.Files collection to display all the images in a

    given
    > directory. The following shows the code I use to create and use this
    > collection:
    >
    > Set myfilesys=Server.CreateObject("Scripting.FileSystemObject")
    > Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
    >
    > When I use a specific file name to access a file, my code works fine:
    >
    > <img src=" & Chr(34) & mydirectory.Name & "/" &
    > mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
    >
    > However, I want to iterate through all the files in the Folder USING

    NUMBERS
    > (I already know how to do it using a For Each statement). But whenever I

    try
    > to do this, I receive an error:
    >
    > <img src=" & Chr(34) & mydirectory.Name & "/" &

    mydirectory.Files(5).Name
    > & Chr(34) & ">
    >
    > Other collections, such as the Request.Form collection allow you to access
    > the collection using either text or numbers, and all books that I have

    read
    > have said that this is true for all collections. Is the Folder.Files
    > collection an exception to this? Is there something else I need to do? If
    > anybody can give me any help on this, I would appreciate it. Thank You.
    > --
    > Nathan Sokalski
    >
    > http://www.students.kutztown.edu/soka0908/HomePage.html
    >
    >
    >
     
    Ray at, Jul 23, 2003
    #2
    1. Advertising

  3. Thank you for that information. The reason I would like to use indexes
    instead of keys is to make the files (which are graphics) into a table which
    will automatically adjust the number of rows when more files are added to
    the directory. Although I do know how to do this using a For Each loop, it
    would be much simpler and more efficient if I could use indexes. But I guess
    I just have to look at this as another good challenge and learning
    experience. Thanks.
    --
    Nathan Sokalski

    http://www.students.kutztown.edu/soka0908/HomePage.html

    "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    message news:...
    > The files collection doesn't support referencing an item by its index.

    Why?
    > There's probably a reason. But you can only reference it by its key,

    which
    > is the file name. Mind if I ask why you want to do this?
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    > > I am using the Folder.Files collection to display all the images in a

    > given
    > > directory. The following shows the code I use to create and use this
    > > collection:
    > >
    > > Set myfilesys=Server.CreateObject("Scripting.FileSystemObject")
    > > Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
    > >
    > > When I use a specific file name to access a file, my code works fine:
    > >
    > > <img src=" & Chr(34) & mydirectory.Name & "/" &
    > > mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
    > >
    > > However, I want to iterate through all the files in the Folder USING

    > NUMBERS
    > > (I already know how to do it using a For Each statement). But whenever I

    > try
    > > to do this, I receive an error:
    > >
    > > <img src=" & Chr(34) & mydirectory.Name & "/" &

    > mydirectory.Files(5).Name
    > > & Chr(34) & ">
    > >
    > > Other collections, such as the Request.Form collection allow you to

    access
    > > the collection using either text or numbers, and all books that I have

    > read
    > > have said that this is true for all collections. Is the Folder.Files
    > > collection an exception to this? Is there something else I need to do?

    If
    > > anybody can give me any help on this, I would appreciate it. Thank You.
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.students.kutztown.edu/soka0908/HomePage.html
    > >
    > >
    > >

    >
    >
     
    Nathan Sokalski, Jul 23, 2003
    #3
  4. Nathan Sokalski

    Chris Barber Guest

    Populate an array and use the array indexes instead?

    Chris.

    "Nathan Sokalski" <> wrote in message
    news:...
    Thank you for that information. The reason I would like to use indexes
    instead of keys is to make the files (which are graphics) into a table which
    will automatically adjust the number of rows when more files are added to
    the directory. Although I do know how to do this using a For Each loop, it
    would be much simpler and more efficient if I could use indexes. But I guess
    I just have to look at this as another good challenge and learning
    experience. Thanks.
    --
    Nathan Sokalski

    http://www.students.kutztown.edu/soka0908/HomePage.html

    "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    message news:...
    > The files collection doesn't support referencing an item by its index.

    Why?
    > There's probably a reason. But you can only reference it by its key,

    which
    > is the file name. Mind if I ask why you want to do this?
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    > > I am using the Folder.Files collection to display all the images in a

    > given
    > > directory. The following shows the code I use to create and use this
    > > collection:
    > >
    > > Set myfilesys=Server.CreateObject("Scripting.FileSystemObject")
    > > Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
    > >
    > > When I use a specific file name to access a file, my code works fine:
    > >
    > > <img src=" & Chr(34) & mydirectory.Name & "/" &
    > > mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
    > >
    > > However, I want to iterate through all the files in the Folder USING

    > NUMBERS
    > > (I already know how to do it using a For Each statement). But whenever I

    > try
    > > to do this, I receive an error:
    > >
    > > <img src=" & Chr(34) & mydirectory.Name & "/" &

    > mydirectory.Files(5).Name
    > > & Chr(34) & ">
    > >
    > > Other collections, such as the Request.Form collection allow you to

    access
    > > the collection using either text or numbers, and all books that I have

    > read
    > > have said that this is true for all collections. Is the Folder.Files
    > > collection an exception to this? Is there something else I need to do?

    If
    > > anybody can give me any help on this, I would appreciate it. Thank You.
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.students.kutztown.edu/soka0908/HomePage.html
    > >
    > >
    > >

    >
    >
     
    Chris Barber, Jul 23, 2003
    #4
  5. The FileSystemObject Files Collection has a .Count property that you can
    use.

    Mike Ober.

    "Nathan Sokalski" <> wrote in message
    news:...
    > Thank you for that information. The reason I would like to use indexes
    > instead of keys is to make the files (which are graphics) into a table

    which
    > will automatically adjust the number of rows when more files are added to
    > the directory. Although I do know how to do this using a For Each loop, it
    > would be much simpler and more efficient if I could use indexes. But I

    guess
    > I just have to look at this as another good challenge and learning
    > experience. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.students.kutztown.edu/soka0908/HomePage.html
    >
     
    Michael D. Ober, Jul 23, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy McCarthy
    Replies:
    3
    Views:
    733
    Anthony J Bybell
    Sep 24, 2004
  2. Bob
    Replies:
    1
    Views:
    394
    Lucas Tam
    Jul 30, 2004
  3. Doug Poland
    Replies:
    9
    Views:
    742
    VisionSet
    Sep 27, 2003
  4. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    613
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  5. mutex
    Replies:
    0
    Views:
    219
    mutex
    Jul 27, 2003
Loading...

Share This Page