No.417
0
回数0
優先度0
発生日2016/11/21
仮完了
完了日
期限
タイトルVBScriptでのUTF-8の取り扱い
サブタイトルエラー文字処理スクリプト
内容
' エラー文字処理スクリプト
' 対象のxmlファイルをフォルダごとこのスクリプトにドラック&ドロップして利用する。
' 現在の対象は、「噛」、「歩」

' 引数なし
If WScript.Arguments.Count = 0 Then WScript.Quit

Set objWS = CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")

' 引数でループ
For i = 0 To WScript.Arguments.Count -1: Do
s = WScript.Arguments.Item(i)
If objFS.FileExists(s) Then
ProcFile(s)
Else
SearchFile(s)
End If
Loop Until 1: Next

r = objWS.PopUp("処理が終了しました。",3,"終了メッセージ",64)
'============================================================



' 以下、サブルーチン

' フォルダ内のファイル---------------------------------------
Sub SearchFile(DPath)
Set Folder = objFS.GetFolder(DPath)
' フォルダ内のフォルダ
'For Each SubFolder In Folder.SubFolders: Do
'SearchFile(SubFolder.Path)
'Loop Until 1: Next
' フォルダ内のファイル
For Each File In Folder.Files: Do
ProcFile(File.Path)
Loop Until 1: Next
End Sub


' ファイル処理メイン ----------------------------------------
Function ProcFile(FPath)

ProcFile = False
If LCase(Right(FPath,3)) <> "xml" Then Exit Function
' ※※※処理実体を記述※※※

set instream = createobject("adodb.stream")
set outstream = createobject("adodb.stream")

set re = new regexp

infilename = FPath
'wscript.echo infilename
instream.open
instream.charset = "UTF-8"
instream.loadfromfile infilename

If err.number > 0 then
wscript.echo "Can't open " & infilename & " for reading."
instream.close
wscript.quit(1)
end if

outstream.open
outstream.charset = "UTF-8"

moveflg = 0

do until instream.eos

line = instream.readtext(-2)
'objWS.PopUp(line)


'「噛」確認
chkCode = ChrW(&H5699)
fixCode = ChrW(&H565B)

re.pattern = chkCode

if re.test(line) then
moveflg = 1
infilepath = objFS.GetParentFolderName(FPath)

if objFS.FolderExists(infilepath & "\org") = False then

objFS.CreateFolder infilepath & "\org"

End if

'修正文字コードに変換
line = re.replace(line, fixCode)

End if


'「歩」確認開始
chkCode = ChrW(&H6b65)
fixCode = ChrW(&H6b69)

re.pattern = chkCode

if re.test(line) then
moveflg = 1
infilepath = objFS.GetParentFolderName(FPath)

if objFS.FolderExists(infilepath & "\org") = False then

objFS.CreateFolder infilepath & "\org"

End if

'修正文字コードに変換
line = re.replace(line, fixCode)

End if
'「歩」確認終了


'ファイル書き込み
outstream.writetext line, 1

loop


' エラー処理
if err.number > 0 then

wscript.echo "Can't open " & outfilename & " for writing."
outstream.close
instream.close
wscript.quit(2)
end if


' 修正すべき文字があった場合の処理
if moveflg = 1 then

objFS.CopyFile infilename, infilepath & "\org\" & objFS.getfilename(infilename)
outfilename = infilepath & "\" & objFS.getfilename(infilename)
'wscript.echo outfilename
objFS.DeleteFile infilename
outstream.savetofile outfilename, 2
'moveflg = 1

End if


' ファイル処理
instream.close
outstream.close
'wscript.quit(0)
ProcFile = True

End Function
' ----------------------------------------------------------
区分
ステータス
中区分個人
小区分DEV
発生元
発生元担当
対応
対応2
連絡先
対応者新実
URL
0
大区分todo
0
登録日2016-11-21 13:00:50
最終アクセス日2016-11-21 13:00:50
更新日2016-11-21 13:00:50