2023年7月9日日曜日

bunnkatu

 setlocal enabledelayedexpansion
rem *********************************************
rem * JOBLOG 件数出力
rem *     DRAG&DROP マルチファイル対応
rem * UPDATE 2023/07/08
rem *********************************************
@echo off
cls
rem echo %1
rem echo %~0
echo ---------------------------------------------
echo  ログからE件数とファイル情報を出力  Ver1.8
echo  %~nx0
echo  %~dp1
echo ---------------------------------------------
echo;
SET /P ANSWER="実行します。よろしいですか (Y/N)?"
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
EXIT /b
:yes
  FOR %%a IN (%*) DO (
    cscript /nologo bin\RecSplit.vbs %%a
  )
  pause
endlocal

Option Explicit
'----------------------------------------------------
' Main
'----------------------------------------------------
Dim Args, sArg1
Dim iCnt

Set Args = WScript.Arguments
If Args.Count < 1 Then
  WScript.Echo "ドラッグ&ドロップしてを実行。"
  WScript.Quit
End If
'WScript.Echo Args.Count
'WScript.Echo sArg1
sArg1 =  Wscript.Arguments(0)
iCnt = SelectKenSu(sArg1)
WScript.Echo ""
If iCnt <> 0 Then
   WScript.Echo "正常 数:" & iCnt & " 件"
Else
   WScript.Echo "異常 数:" & iCnt & " 件"
End If
WScript.Quit (0)
'----------------------------------------------------
' 分割出力
'----------------------------------------------------
Function SelectKenSu(sArg1)
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim sPathIn, sPathOut, sBasePath
Dim fs, fr, fw
Dim sIRec, sORec
Dim sIFile, sOFile, s
    Dim iICnt, iOCnt, iMaxCnt
Dim iIPos, iFPos, intSts, i
Dim iOLRECL

    iOLRECL = 10
SelectKenSu = 0
    sPathIn = sArg1

    iFPos = InStrRev(sPathIn, "\")
    sBasePath = Left(sPathIn,iFPos -1)
    sIFile = Mid(sPathIn,iFPos + 1)
    'sOFile = "結果_" & sIFile & ".txt"
    sOFile = sIFile & ".txt"
    '---------------------------------------
    WScript.Echo "BASEPath  :" & sBasePath 
    WScript.Echo "入力FILE :" & sIFile
    WScript.Echo "出力FILE :" & sOFile
    WScript.Echo ""
    '---------------------------------------
    sPathIn  = sBasePath & "\" & sIFile
    sPathOut = sBasePath & "\結果\" & sOFile

    Set fs = CreateObject("Scripting.FileSystemObject")
    If Not (fs.FolderExists(sBasePath & "\結果")) Then
fs.CreateFolder(sBasePath & "\結果")
    End If
    
    If  fs.FileExists(sPathIn) Then
        Set fr = fs.OpenTextFile(sPathIn, ForReading)
        Set fw = fs.OpenTextFile(sPathOut, ForWriting, True)
        iICnt = 1
        Do While Not fr.AtEndOfStream
            sIRec = fr.ReadLine
            iMaxCnt = len(sIRec)/iOLRECL
            iIPos = 1
            For i = 1 To iMaxCnt
                  sORec = Mid(sIRec,iIPos,iOLRECL)
                  fw.WriteLine sORec
                  iOCnt = iOCnt + 1
                  iIPos = iIPos + iOLRECL
            Next
            iICnt = iICnt + 1
        Loop
        WScript.Echo "入力行数:" & iICnt
        WScript.Echo "出力行数:" & iOCnt
        fr.Close:fw.Close
        Set fr = Nothing:Set fw = Nothing
        intSts = 0
    Else
        'Call MsgBox("テキストが見つからない!", 48, "エラー")
        intSts = 1
    End If
    Set fs = Nothing
    SelectKenSu = iOCnt
End Function