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

VBSの質問です
hogeフォルダにvbsが置かれています
hogeフォルダ内のサブフォルダ内のa.htmlを探し
hogeフォルダ内の全htmlファイルを取得し
一つ上のフォルダのテキストファイルに入力したいと思うのですがうまく動きません
どうすれば動くでしょうか?よろしくお願いします

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

▽最新の回答へ

質問者から
targetFolderName = "."

Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set targetFolder = fs.getFolder(targetFolderName)
Set parentFolder = targetFolder.ParentFolder
Set output = fs.CreateTextFile(parentFolder.Path & "\list.html", True)
For Each folder In targetFolder.SubFolders
 For Each f In folder.Files
 If f.Name = "kekka.html" Then
 output.WriteLine "http://" & targetFolder.Name & "/" & folder.Name & "/"
 End If
 Next
Next
targetFolderName = "../"
For Each folder In targetFolder.files
 For Each f In folder.Files
 If f.Name = "*.html" Then
 output.WriteLine "http://" & targetFolder.Name & "/" & folder.Name & "/"
 End If
 Next
Next
output.Close


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

以下の二つの質問のスクリプトを、ひとつにまとめます。
http://q.hatena.ne.jp/1417475886
http://q.hatena.ne.jp/1417531694

こんな感じになります。

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 "アドレス一覧"

' hoge フォルダのサブフォルダにある a.html を探す
For Each folder In targetFolder.SubFolders
 For Each f In folder.Files
 If f.Name = "a.html" Then
 output.WriteLine "http://" & targetFolder.Name & "/" & folder.Name & "/" & f.Name
 End If
 Next
Next

' hoge フォルダにある .html ファイルを探す
For Each f In targetFolder.Files
 If fs.GetExtensionName(f.Path) = "html" Then
 output.WriteLine "http://" & targetFolder.Name & "/" & f.Name
 End If
Next

output.WriteLine "以上"
output.Close

fashudifhajsさんのコメント
ありがとうございます!
関連質問

●質問をもっと探す●



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