カレントフォルダの中に
ああ1.html
ああ2.html
ああ10.html
ああ22.html
というファイルがあるのですが
ああ1.html
ああ2.html
のように ああ の後に数字が1文字しかないファイルだけ結合するスクリプトを教えてください
このようなスクリプトをくみましたがうまくいきません
Const InFolder = "ああ\.html"
Const OutFileName = "ketugo.html"
Const ForReading = 1, ForWriting = 2
Dim fso, f, fc, fn, InFile, OutFile
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(InFolder)
Set fc = f.Files
Set OutFile = fso.OpenTextFile(OutFileName, ForWriting, true)
For Each fn in fc
Set InFile = fso.OpenTextFile(fn, ForReading)
OutFile.Write(InFile.ReadAll())
InFile.Close()
Next
OutFile.Close()
Const InFolder = "ああ" Const OutFileName = "ketugo.html" Const ForReading = 1, ForWriting = 2 Dim fso, f, fc, fn, InFile, OutFile Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set objWshShell = WScript.CreateObject("WScript.Shell") Set RE = CreateObject("VBScript.RegExp") RE.Pattern = InFolder & "*" strPATH = Wscript.ScriptFullName InFolder2 = Left(strPATH,InStrRev(strPATH,"\")-1) Set f = fso.GetFolder(InFolder2) Set fc = f.Files Set OutFile = fso.OpenTextFile(OutFileName, ForWriting, true) For Each fn in fc If right(fn.name,5)=".html" and RE.Test(fn.name) and len(fn.name) = len(InFolder)+6 then c= mid(fn.name,len(InFolder)+1,1) if c>="0" and c<="9" then Set InFile = fso.OpenTextFile(fn, ForReading) OutFile.Write(InFile.ReadAll()) InFile.Close() end if end if Next OutFile.Close() Set fso = Nothing Set RE = Nothing
けっこう修正しないと ちゃんと動きませんでした。
これまでにも利用してきたRegExpを使った例
Const InFolder = "ああ.html" Const OutFileName = "ketugo.html" Const ForReading = 1, ForWriting = 2 Dim fso, f, fc, fn, InFile, OutFile Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(InFolder) Set fc = f.Files Set OutFile = fso.OpenTextFile(OutFileName, ForWriting, true) Set objEXP = New RegExp objEXP.Pattern = "^ああ[0-9]\.html$" For Each fn in fc If objEXP.Test(fn.Name) THEN Set InFile = fso.OpenTextFile(fn, ForReading) OutFile.Write(InFile.ReadAll()) InFile.Close() End If Next
元のソースに加えたのは下記2点です。
' パターン検索の準備 Set objEXP = New RegExp objEXP.Pattern = "^ああ[0-9]\.html$" ' 下記の設定はデフォルトがFALSEなので今回は省きました。 objEXP.Multiline = False objEXP.Global = False
' パターン適合性のテスト If objEXP.Test(fn.Name) THEN End If
コメント(0件)