通过FileSystemObject集合进行迭代时的性能调整

问题描述:

我不知道系统在此行的内存中存储了多少For Each objFile in objFolder.Files以及使用诸如objFile.Files.Count之类的迭代是否更有利。有谁知道如果使用下面的代码会造成任何重大的性能问题?通过FileSystemObject集合进行迭代时的性能调整

Dim objFSO 
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 

'Get the folder object associated with the directory 
Dim objFolder 
Set objFolder = objFSO.GetFolder("C:\InetPub\wwwroot") 

Response.Write "The files found in " & objFolder.Name & ":<br>" 

'Loop through the Files collection 
Dim objFile 
For Each objFile in objFolder.Files 
    Response.Write objFile.Name & "<br>" 
Next 

'Clean up! 
Set objFolder = Nothing 
Set objFile = Nothing 
Set objFSO = Nothing 

我不知道有多少系统存储在内存中该行对于每个OBJFILE在objFolder.Files

不知道你的意思,但这种过度的集合将只循环的文件对象这将不会使用大量的内存。这个调用显然不会加载内存中的文件的内容,如果这是你的问题。