我有一个我目前正在使用的VB脚本并且运行良好,但是我希望有一种方法来指定列出的文件类型,并且我可以使用它。 d也想列出子目录。不是子目录内容,只是它们的名称。这就是我所拥有的:
Dim ls, fsObj, fd, fs, fl, tf
ls = ""
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set fd = fsObj.GetFolder(".")
set fs = fd.Files
For Each fl in fs
ls = ls & "<a href=""" & fl.name & chr(34) & Chr(62) & fl.name & chr
(60) & chr(47) & chr(97) & chr(62) & chr(10) & "</br>"
Next
Set tf = fsObj.OpenTextFile("dirlist.html", 2, True, True)
tf.WriteLine ls
tf.Close
Set fsObj = Nothing
我可以做得更轻松,更漂亮但除了文件夹和文件类型问题之外,这对我有用。
答案 0 :(得分:0)
Dim ls, fsObj, fd, fs, fl, sfs, sf, tf
' specify the file extensions to list
dim fileTypes
fileTypes = Array("pdf","txt","asp")
ls = ""
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set fd = fsObj.GetFolder(".")
set fs = fd.Files
For Each fl in fs
' check whether the extension matches
if arrayContains(fileTypes, fsObj.GetExtensionName(fl.name)) then
ls = ls & "<a href=""" & fl.name & chr(34) & Chr(62) & fl.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "</br>"
end if
Next
' list subfolders
set sfs = fd.SubFolders
For Each sf in sfs
ls = ls & "<a href=""" & sf.name & chr(34) & Chr(62) & sf.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "</br>"
Next
Set tf = fsObj.OpenTextFile("dirlist.html", 2, True, True)
tf.WriteLine ls
tf.Close
Set fsObj = Nothing
function arrayContains (arr, val)
dim found
found = false
for i = 0 to ubound(arr)
if arr(i) = val then
found = true
exit for
end if
next
arrayContains = found
end function
答案 1 :(得分:0)
这是一个网页版本。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<%
Dim ls, fsObj, fd, fs, fl, sfs, sf, tf
'specify the file extensions to list
dim fileTypes
fileTypes = Array("pdf","txt","asp")
ls = ""
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set fd = fsObj.GetFolder(".")
set fs = fd.Files
For Each fl in fs
'check whether the extension matches
if arrayContains(fileTypes, fsObj.GetExtensionName(fl.name)) then
'ls = ls & "<a href=""" & fl.name & chr(34) & Chr(62) & fl.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "<br>"
response.write ( "<a href=""" & fl.name & chr(34) & Chr(62) & fl.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "<br>" )
end if
Next
' list subfolders
set sfs = fd.SubFolders
For Each sf in sfs
'ls = ls & "<a href=""" & sf.name & chr(34) & Chr(62) & sf.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "<br>"
response.write( "<a href=""" & sf.name & chr(34) & Chr(62) & sf.name & chr(60) & chr(47) & chr(97) & chr(62) & chr(10) & "<br>" )
Next
'Set tf = fsObj.OpenTextFile("dirlist.html", 2, True, True)
'tf.WriteLine ls
'tf.Close
Set fsObj = Nothing
function arrayContains (arr, val)
dim found
found = false
for i = 0 to ubound(arr)
if arr(i) = val then
found = true
exit for
end if
next
arrayContains = found
end function
%>