人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

VBSの質問です
hoge フォルダの中に
a.html
b.html
c.html
d.html




というようにテキストファイルがたくさん入っています

hogeの一つ上のフォルダに以下のテキストが入力されたhtmlファイルを作りたいのですがどのようなVBSを組めばいいでしょうか?教えてください

hoge.html
***************
<tr><td>http://hoge/a.html</td><td>http://hoge/b.html</td></tr>
<tr><td>http://hoge/c.html</td><td>http://hoge/d.html</td></tr>
<tr><td>http://hoge/・.html</td><td>http://hoge/・.html</td></tr>



***********

●質問者: fashudifhajs
●カテゴリ:コンピュータ
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● a-kuma3
●300ポイント ベストアンサー

こんな感じになります。

targetFolderName = "D:\test\hoge"  ' ※ hoge フォルダのパス

Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set targetFolder = fs.getFolder(targetFolderName)

Set parentFolder = targetFolder.ParentFolder
Set output = fs.CreateTextFile(parentFolder.Path & "\list.html", True)
output.WriteLine "<table>"

For Each f In targetFolder.Files
 If fs.GetExtensionName(f.Path) = "html" Then
 output.WriteLine "<tr><td>http://" & targetFolder.Name & "/" & f.Name & "</td></tr>"
 End If
Next

output.WriteLine "</table>"
output.Close

他で質問されていることも考慮して、以下の処理もしています。


追記です。

左端 真ん中 右端で使っているタグは違います

失礼しました。2列の TABLE なんですね。
では、こんな感じでは、いかがでしょうか。

targetFolderName = "D:\test\hoge"  ' ※ hoge フォルダのパス

Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set targetFolder = fs.getFolder(targetFolderName)

Set parentFolder = targetFolder.ParentFolder
Set output = fs.CreateTextFile(parentFolder.Path & "\list.html", True)
output.WriteLine "<table>"

odd = True
For Each f In targetFolder.Files
 If fs.GetExtensionName(f.Path) = "html" Then
 If odd Then
 output.Write "<tr><td>http://" & targetFolder.Name & "/" & f.Name & "</td>"
 odd = False
 Else
 output.WriteLine "<td>http://" & targetFolder.Name & "/" & f.Name & "</td></tr>"
 odd = True
 End If
 End If
Next

output.WriteLine "</table>"
output.Close

fashudifhajsさんのコメント
左端 真ん中 右端で使っているタグは違います

a-kuma3さんのコメント
>> 左端 真ん中 右端で使っているタグは違います << 失礼しました。2列の TABLE なんですね。 修正したスクリプトを回答に追記しました。
関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ