出来るのだASP Q&A掲示板(過去LOG)
訪問数 52046
昨日 889
今日 776 【PR】 パソコン入門からIT専門書まで幅広く取り揃えています。セブン-イレブン受取り手数料無料のセブンアンドワイ。 |
![]() ![]() ![]() ![]() ![]() |
[3708] INIファイルを読み込みHTMLの一文をテキストファイルに出力したいのですが。。。 |
投稿者:Ruiさん 2003/10/07 17:15:14 |
はじめまして、Ruiと申します。 VBScriptで、INIファイルを読み込みHTMLの一文をテキストファイルに出力したいのですが、上手くいきません。 仕様については、 ・未定義の場合はエラーを出力 ・読み込んだ値の定義がNULLだった場合、その部分の定義を出力しない。 ・waku=noneが定義 です。 INIファイルの定義は下の様になっています。 [TABLE] waku=none BORDER=1 WIDTH="500" HEIGHT=100 CELLPADDING=5 CELLSPACING=20 ALIGN=right BGCOLOR=#rrggbb ファイル出力結果は、下のものです。 <TABLE BORDER=1 WIDTH="500" HEIGHT="100" CELLPADDING="5" CELLSPACING="20" ALIGN="right" BGCOLOR="#rrggbb"> <TR> <TD> </TD> </TR> <TR> <TD> </TD> </TR> </TABLE> とりあえずINIファイルの読み込みの途中まで作成したので、それを下に記しておきます。 <job id="Gridmaker"> <comment> '**************************************************************************** '* ファイル名 : Gridmaker.wsf '* 概要 : 表枠組みの処理 '* 作成者 : ---- '* 作成日 : 2003/10/01 '* 履歴 : '* 備考 : '**************************************************************************** </comment> <script language="VBScript" src="./Gridmaker_conf.inc"/> <script language="VBScript"> Option Explicit '**************************************************************************** ' 定数 定義 '**************************************************************************** '--- Gridmaker_conf.incで定義 ---- '**************************************************************************** ' Main '**************************************************************************** 'On Error Resume Next Dim bool_rtn 'Function戻り値用 Dim bool_ErrFlg Dim strWkMsg Dim strErrMsg '初期化 bool_ErrFlg = GRIDMAKER_OK strWkMsg = "" strErrMsg = "" '■処理開始ログ出力■ Call writeLog(LOG_FILEPATH, INFO, MSG0001_I, "") '■INIファイルの読込み&解析■ bool_rtn = ReadIniFilePath(INI_FILE_DIRPATH, INI_FILE_NAME_MISYU, strErrMsg) If bool_rtn = False Then Call writeLog(LOG_FILEPATH, ERROR, strErrMsg, "") bool_ErrFlg = GRIDMAKER_NG End If '■処理終了ログ出力■ Call writeLog(LOG_FILEPATH, INFO, MSG0002_I & Chr(13) & Chr(10), "") '■終了処理■ '正常終了の場合 If bool_ErrFlg = GRIDMAKER_OK Then Wscript.Quit(0) '異常終了の場合 Else Wscript.Quit(1) End If '**************************************************************************** ' 関数 '**************************************************************************** '============================================================================ ' INIファイル関連 '============================================================================ '**************************************************************************** '* 関数名 : ReadIniFilePath() '* 処理 : INIファイルの読込 '* 引数 : ARG1 - [IN] 対象ディレクトリパス '* : ARG2 - [IN] INIファイル名 '* : ARG3 - [OUT] エラーメッセージ '* 戻り値 : True/False '* 作成者 : ---- '* 作成日 : 2003/10/01 '* 履歴 : '* 備考 : '**************************************************************************** Function ReadIniFilePath( _ in_str_DirPath, _ in_str_FileName, _ ByRef out_err_msg _ ) 'On Error Resume Next Dim bool_rtn 'Function戻り値用 Dim strValue Dim strWkMsg Dim str_IniFilePath ReadIniFilePath = False out_err_msg = "" strValue = "" strWkMsg = "" str_IniFilePath = "" 'ファイルの存在チェック bool_rtn = CheckFilePath(in_str_DirPath, _ in_str_FileName, _ str_IniFilePath, _ out_err_msg) If bool_rtn = False Then '処理中断 Exit Function End If '値の取得 bool_rtn = GetKeyValue( in_str_DirPath, _ in_str_FileName, _ INI_SESSION_TABLE, _ INI_KEY_BGCOLOR, _ strValue, _ out_err_msg) If bool_rtn = True Then strWkMsg = "値:" & strValue Call writeLog(LOG_FILEPATH, INFO, strWkMsg, "") End If ReadIniFilePath = bool_rtn End Function '**************************************************************************** '* 関数名 : CheckFilePath() '* 処理 : INIファイルパスの存在チェック '* 引数 : ARG1 - [IN] 対象ディレクトリパス '* : ARG2 - [IN] ファイル名 '* : ARG3 - [OUT] 処理対象ファイルパス '* : ARG4 - [OUT] エラーメッセージ '* 戻り値 : True/False '* 作成者 : ---- '* 作成日 : 2003/10/01 '* 履歴 : '* 備考 : '**************************************************************************** Function CheckFilePath(in_str_DirPath, _ in_str_FileName, _ ByRef out_str_FilePath, _ ByRef out_err_msg) 'On Error Resume Next Dim objFlSys ' ディレクトリオブジェクト Dim objFile ' オブジェクト Dim objFileName ' ファイルオブジェクト Dim strDefFileName ' ファイル名 Dim strDefFilePath ' ファイルパス Dim strWkFileName ' ファイル名(作業用) CheckFilePath = False out_str_FilePath = "" out_err_msg = "" strDefFilePath = "" 'ファイル名の取得 strDefFileName = Replace(in_str_FileName,"\","") 'ファイルシステムオブジェクト Set objFlSys = CreateObject("Scripting.FileSystemObject") 'ディレクトリの取得 Set objFile = objFlSys.GetFolder(in_str_DirPath) 'ディレクトリが存在しない If Err.Number <> 0 Then out_err_msg = MSG3003_E ' オブジェクトの破棄 Set objFlSys = Nothing Exit Function End If 'ファイルがなくなるまでループする For Each objFileName In objFile.Files 'ファイル名を取得 strWkFileName = objFileName.Name '存在するファイルが指定のファイル名と一致するとき If strWkFileName = strDefFileName Then strDefFilePath = objFileName.Path Exit for End If Next ' オブジェクトの破棄 Set objFlSys = Nothing Set objFile = Nothing ' デフォルトファイル名のファイルが存在する場合 If strDefFilePath <> "" Then ' 返り値にデフォルトファイルパスを返す out_str_FilePath = strDefFilePath '上記以外の場合、エラー Else out_err_msg = MSG3002_E Exit Function End If CheckFilePath = True End Function '**************************************************************************** '* 関数名 : GetKeyValue '* 処理 : セッション名およびキー名から設定された値を取得する '* 引数 : ARG1 - [IN] INIファイルのディレクトリパス '* : ARG2 - [IN] INIファイル名 '* : ARG3 - [IN] セッション名 '* : ARG4 - [IN] キー名 '* : ARG5 - [OUT] 設定値 '* : ARG6 - [OUT] エラーメッセージ '* 戻り値 : True/False '* 作成者 : ---- '* 作成日 : 2003/10/01 '* 履歴 : '* 備考 : '**************************************************************************** Function GetKeyValue( _ in_str_DirPath, _ in_str_FileName, _ in_str_Session, _ in_str_Key, _ ByRef out_str_Value, _ ByRef out_err_msg _ ) 'On Error Resume Next Dim bool_rtn 'Function戻り値用 Dim objFs 'FileSystemオブジェト Dim objTs 'TextStreamオブジェクト Dim strSession 'セッション名 Dim strKey 'キー名 Dim strWkBuf '読み込み用変数 Dim bool_Session_flg '該当のセッションに相当するかどうか Dim strIniFilePath 'Iniファイルパス GetKeyValue = False out_str_Value = "" out_err_msg = "" strWkBuf = "" bool_Session_flg = False strIniFilePath = "" ' 前後の空白を除く strSession = Trim(in_str_Session) ' セッション名が定義されているかどうかのチェック If strSession = "" Then ' セッション名が定義されていません。 out_err_msg = MSG3004_E Exit Function End If ' セッション名(取得用)の設定 strSession = BRACKET_START & LCase(strSession) & BRACKET_END ' キー名の設定 strKey = Trim(in_str_Key) If strKey <> "" Then strKey = LCase(strKey) + STR_EQUAL End If 'ファイルの存在チェック bool_rtn = CheckFilePath(in_str_DirPath, _ in_str_FileName, _ strIniFilePath, _ out_err_msg) If bool_rtn = False Then '処理中断 Exit Function End If Set objFs = Wscript.CreateObject("Scripting.FileSystemObject") 'ファイルオープン Set objTs = objFs.OpenTextFile(strIniFilePath, OPEN_MODE_READ, True) bool_rtn = False 'ファイルから一行ずつ読み出す Do While Not objTs.AtEndOfStream '一行読み込み strWkBuf = objTs.ReadLine ' ' セッション定義行かどうかの判断 ' If Left(Trim(strWkBuf),1) = BRACKET_START Then ' ' 該当のセッションの場合 ' If LCase(strWkBuf) = strSession Then ' ' フラグを立てる ' bool_Session_flg = True ' ' 該当のセッションではない ' Else ' ' 既に該当のセッションのフラグがたっていた場合は ' If bool_Session_flg = True Then Exit Do End If End If Else ' ' 該当のセッションに該当する場合 ' If bool_Session_flg = True Then ' '指定されたキー名と一致する場合 ' If Left(LCase(strWkBuf), Len(strKey)) = strKey Then ' ' 値の取得 ' out_str_Value = Trim(Replace(Right(strWkBuf, Len(strWkBuf) - Len(strKey)), """","")) bool_rtn = True Exit Do End If End IF End If Loop '該当のセッションが存在しなかった場合 If bool_Session_flg = False Then ' '指定されたセッションがない ' out_err_msg = MSG3006_E & _ "(INIファイルパス:" & strIniFilePath & _ ", セッション名:" & in_str_Session & ")" '該当のキーが存在しなかった場合 ElseIf bool_rtn = False Then ' '検索は終了しているとみなす ' out_err_msg = MSG3005_E & _ "(INIファイルパス:" & strIniFilePath & _ ", セッション名:" & in_str_Session & _ ", キー名:" & in_str_Key & ")" End If 'ファイルクローズ objTs.Close Set objFs = Nothing GetKeyValue = bool_rtn End Function '**************************************************************************** '* FileUtil '**************************************************************************** '**************************************************************************** '* 関数名 : CombineFilePath '* 処理 : ディレクトリパスとファイル名の結合 '* 引数 : ARG1 - [IN] ディレクトリパス '* ARG2 - [IN] ファイル名 '* 戻り値 : ファイルパス '* 作成者 : ---- '* 作成日 : 2003/06/04 '* 履歴 : '* 備考 : '**************************************************************************** Function CombineFilePath(in_str_DirPath, in_str_FileName) On Error Resume Next CombineFilePath = "" Dim strDirPath Dim strFileName strDirPath = Trim(in_str_DirPath) strFileName = Trim(in_str_FileName) 'ディレクトリパスの最後が\でない場合 If Left(strDirPath, 1) <> "\" Then ' \を追加する strDirPath = strDirPath & "\" End If 'ファイル名に\が含まれてるといけないのでリプレースをかける strFileName = Replace(strFileName,"\","") ' ファイルパスの作成 CombineFilePath = strDirPath & strFileName End Function '**************************************************************************** '* 関数名 : GetFileName '* 処理 : ファイル名(拡張子なし)の取得 '* 引数 : ARG1 - [IN] ファイル名 '* 戻り値 : ファイル名(拡張子なし) '* 作成者 : ---- '* 作成日 : 2003/06/18 '* 履歴 : '* 備考 : '**************************************************************************** Function GetFileName(in_str_FileName) On Error Resume Next GetFileName = "" Dim strFileName Dim intPlace strFileName = Replace(Trim(in_str_FileName),"\","") '拡張子までの文字位置を返す intPlace = InStrRev(strFileName,".") '拡張子までの文字位置を返す If intPlace > 0 Then 'ファイル名の取得 strFileName = Mid(strFileName, 1, intPlace - 1) End If GetFileName = strFileName End Function '**************************************************************************** '* 関数名 : GetFileExt '* 処理 : ファイルの拡張子を取得 '* 引数 : ARG1 - [IN] ファイル名 '* 戻り値 : ファイルの拡張子 '* 作成者 : ---- '* 作成日 : 2003/06/18 '* 履歴 : '* 備考 : 拡張子が見つからない場合、NULLを返す '**************************************************************************** Function GetFileExt(in_str_FileName) On Error Resume Next GetFileExt = "" Dim strFile Dim intPlace strFile = Replace(Trim(in_str_FileName),"\","") '拡張子までの文字位置を返す intPlace = InStrRev(strFile,".") If intPlace > 0 Then '拡張子の取得 strFile = Mid(strFile, intPlace + 1, Len(strFile)) Else strFile = "" End If GetFileExt = strFile End Function '**************************************************************************** '* 関数名 : deleteFile '* 処理 : ファイルの削除 '* 引数 : ARG1 - [IN] 削除するファイルのフルパス '* :ARG2 - [OUT] エラーメッセージ '* 戻り値 : True/False '* 作成者 : ---- '* 作成日 : 2003/05/23 '* 履歴 : '* 備考 : '**************************************************************************** Function deleteFile(in_str_FilePath, out_errMsg) On Error Resume Next Dim objFileSys Dim objFile deleteFile = False out_errMsg = "" 'ファイルシステムオブジェクト Set objFileSys = CreateObject("Scripting.FileSystemObject") '削除ファイルのセット Set objFile = objFileSys.GetFile(in_str_FilePath) 'ファイルの削除 objFile.Delete If Err.Number <> 0 Then out_errMsg = Err.Description Else deleteFile = True End If 'オブジェクトの破棄 Set objFile = Nothing Set objFileSys = Nothing End Function '**************************************************************************** '* DateUtil '**************************************************************************** '**************************************************************************** '* 関数名 : isDate '* 処理 : 日付妥当性チェック '* 引数 : ARG1 - [IN] 年・・・YYYY形式 '* : ARG2 - [IN] 月・・・MM形式 '* : ARG2 - [IN] 日・・・DD形式 '* 戻り値 : なし '* 作成者 : ---- '* 作成日 : 2003/06/20 '* 履歴 : '* 備考 : '**************************************************************************** Function CheckDate(strYear,strMonth,strDay) On Error Resume Next Dim dteTmp On Error Resume Next CheckDate=DateValue (strYear & "/" & strMonth & "/" & strDay) End Function '**************************************************************************** '* その他 '**************************************************************************** '**************************************************************************** '* 関数名 : sub_wait '* 処理 : Wait処理 '* 引数 : ARG1 - [IN] 待ち時間 '* 戻り値 : なし '* 作成者 : ---- '* 作成日 : 2003/06/18 '* 履歴 : '* 備考 : '**************************************************************************** Sub sub_wait(intWaitSec) Dim time1 Dim time2 time1 = Now Do time2 = Now If time1 + TimeSerial(0,0,intWaitSec) <= time2 then Exit Do End If Loop End Sub '**************************************************************************** '* ログ関連 '**************************************************************************** '**************************************************************************** '* 関数名 : writeLog '* 処理 : ログファイルを出力します。 '* 引数 : ARG1 - [IN] ログファイルパス '* : ARG2 - [IN] ログ種別 '* : ARG3 - [IN] ログメッセージ '* : ARG4 - [IN] ログ詳細情報 '* 戻り値 : なし '* 作成者 : ---- '* 作成日 : 2003/06/02 '* 履歴 : '* 備考 : '**************************************************************************** Sub writeLog( _ ByVal strLogFile, _ ByVal strKind, _ ByVal strMessage, _ ByVal strDetail _ ) Dim objFs 'FileSystemオブジェト Dim objTs 'TextStreamオブジェクト Dim strLogFormat 'ログフォーマット Set objFs = Wscript.CreateObject("Scripting.FileSystemObject") 'ファイルオープン Set objTs = objFs.OpenTextFile(strLogFile, 8, True) 'ログ文字列の生成(YYYY/MM/DD HH:MM:SS strKind strMessage) strLogFormat = Right("0000" & CStr(Year(Now)), 4) & "/" & Right("00" & CStr(Month(Now)), 2) & "/" & Right("00" & CStr(Day(Now)), 2) & " " & _ Right("00" & CStr(Hour(Now)), 2) & ":" & Right("00" & CStr(Minute(Now)), 2) & ":" & Right("00" & CStr(Second(Now)), 2) & " " & _ strKind & " " & _ strMessage '詳細情報がある場合 If strDetail <> "" Then strLogFormat = strLogFormat & vbCrLf & Space(28) & strDetail End If 'ログ種別がErrorの場合 If strKind = Error Then If Err.Number <> 0 Then ' strLogFormat = strLogFormat & vbCrLf & Space(28) & "Err.Number:" & Err.Number & " " & _ ' "Err.Description:" & Err.Description & " " & _ ' "Err.Source:" & Err.Source strLogFormat = strLogFormat & vbCrLf & Space(28) & "エラー番号:" & Err.Number & _ vbCrLf & Space(28) & "エラー内容:" & Err.Description & _ vbCrLf & Space(28) & "エラーソース:" & Err.Source End If End If 'ログ書き込み objTs.WriteLine strLogFormat 'ファイルクローズ objTs.Close Set objFs = Nothing End Sub </script> </job> です。 この先どのようにしていったらよいのかで詰まっています。 アドバイスなどいただけるとうれしいです。 長くて申し訳ありません。 |
![]() ![]() |
![]() |
TreeBBS For ASP V.0.1.3 |