Unable to access ASP FileSystemObject collection by index

I'm out of my mind? I cannot find a way to get the first file in a folder with FileSystemObject (classic ASP). In most collections, you might think that an index of 0 or 1 might work, but IIS says "Invalid call or procedure argument."

None of these last two lines work:

Set oFileScripting = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFileScripting.GetFolder(sFolder)
Set oFiles = oFolder.Files
If oFiles.Count = 0 Then Response.Write "no files"
Response.Write oFiles(0).Name
Response.Write oFiles.Item(1).Name

Am I really very stupid, or is there no way to use the index to access this particular collection?

+3
source share
2 answers

. , , , File .

ReDim FileArray(oFiles.Count)

i = 0
For Each oFile In oFiles
   FileArray(i) = oFile.Name
   i = i + 1
Next

Set oFile = oFileScripting.GetFile(sFolder + "\" + FileArray(0))

, , , .

+3

, :

Set oFileScripting = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFileScripting.GetFolder(sFolder)
Set oFiles = oFolder.Files
If oFiles.Count = 0 Then Response.Write "no files"

i = 0
For Each oFile In oFiles
   Response.Write i & " = " & oFile.Name
   i = i + 1
Next
0

Source: https://habr.com/ru/post/1708097/


All Articles