2017-01-22 7 views
0

私は現在使用しているVBスクリプトを持っていますが、うまくいきますが、どのファイルタイプが指定されているかを指定する方法があります。また、サブディレクトリを一覧表示するのも好きです。サブディレクトリの内容ではなく、その名前だけです。これは私が持っているものです:VBスクリプトは、htmlに出力されたファイルとフォルダを一覧表示する

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
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 
+0

ケビンは素晴らしい作品ありがとうございました!!!!私は別のアイデアをhtmlのページに入れて、出力が同じページに書き込まれるようにすることができますか? – Greg

+0

あなたはファイルに保存するのではなく、出力をresponse.writeするだけです。 –

+0

メイト申し訳ありませんが、それはどういう意味ですか?私はVBスクリプティングから始めています。まだその章にはいらないよ。 – Greg

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 

%> 

関連する問題