Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\Inetpub\wwwroot\tsggl\tsgtz\")
Set fc = f.File
Dim i = 0
For Each f1 in fc
array1(i)=f1.name
i=i+1
Next
问题出在哪里?
...全文
1104打赏收藏
菜鸟问题,如何读取目录下文件
Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder("C:\Inetpub\wwwroot\tsggl\tsgtz\") Set fc = f.File Dim i = 0 For Each f1 in fc array1(i)=f1.name i=i+1 Next 问题出在哪里?
<% option explicit%>
这个文件列出了当前运行文件所在文件夹的目录结构<Br><Br>
当前文件夹是
<%
Dim objFSO,objFolder
set objFSO = server.createObject("scripting.fileSystemObject")
set objFolder = objFSO.getFolder(server.mapPath(".\"))
response.write objFolder.path&"<BR>"
search objFolder,1
sub search(whichFolder,layer)
Dim objFile,objSubFolder,objDelFile
Dim i
set objDelFile = server.createObject("scripting.fileSystemObject")
for i = 1 to layer-1
response.write " "
next
response.write "["&whichFolder.name&"]"&"<BR>"
if whichFolder.files.count <> 0 then
For Each objFile in whichFolder.Files
for i = 1 to layer
response.write " "
next
response.write objFile.name&"<BR>"
next
end if
if whichFolder.subFolders.count <> 0 then
For Each objSubFolder in whichFolder.SubFolders
search objSubFolder,layer+1
next
end if
end sub
%>
把这个代码存一个.asp文件,在IIS中设置好虚拟目录,它就可以遍历列出虚拟目录下的所有文件,包含子文件夹下的文件。