Files Collection

Results 1 to 2 of 2

Thread: Files Collection

  1. #1
    Join Date
    Dec 1969
    Posts
    236

    Default Files Collection

    I&#039m trying to access a particular a random file from the files collection of the Scripting.Folder object. I can read the files if I skip through in For Each .. Next method but I can&#039t get a result from files.Count or files(index). Here is a snippet of code:<BR><BR>set thefolder = fso.GetFolder(&#060;folder dir&#062;)<BR>set thefiles = thefolder.Files<BR>Randomize<BR>fileNum = Int(thefiles.Count * Rnd)<BR>set thefile = thefolder.Files(fileNum)<BR>or even<BR>set thefile = thefolder.Files(1)<BR><BR>Any advice?<BR><BR>Thanks.

  2. #2
    Chris Willey Guest

    Default RE: Files Collection

    I&#039ve played around with this for a bit, and the best I can come up with is to get the random number and then break the For...Each loop after the random number is hit. There is the Item property of the Files collection, but it doesn&#039t accept a number, only a file name.<BR><BR>Here&#039s what I have (you&#039ve probably already done this, but anyway):<BR><BR>set thefolder = fso.GetFolder(&#060;path&#062;)<BR>set thefiles = thefolder.Files<BR>Randomize<BR>fileNum = Int(thefiles.Count * Rnd)<BR>x = 0<BR>For Each fileobj in thefiles<BR> x = x + 1<BR> If x = fileNum Then<BR> Response.Write(fileobj.Name)<BR> Exit For<BR> End If<BR>Next<BR>

Posting Permissions

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