'Master
Option Explicit
'Public cnt As Long
' テキストファイル読み込みサンプル3(FSO)
' 参照設定:Microsoft Scripting Runtime
Sub READ_TextFile3()
' 読み込むファイル名(固定)
Const cnsFILENAME = "L:\wp\xls\Fuji.txt"
Dim FSO As New FileSystemObject ' FileSystemObject
Dim TS As TextStream ' TextStream
Dim strREC As String ' 読み込んだレコード内容
Dim GYO As Long ' 収容するセルの行
Dim i As Long 'ループ回数変数
Dim cnt, rownum As Long '
Dim strSplit As Variant 'リビジョンでsplitする
' 指定ファイルをOPEN(入力モード)
Set TS = FSO.opentextfile(cnsFILENAME, ForReading)
GYO = 1
'リビジョンの数を最初に数えておく
'cnt はローカルになっちゃうから、値を渡さないとあかんよ
Do Until TS.AtEndOfStream
strREC = TS.ReadLine
If InStr(strREC, "リビジョン") Then
cnt = cnt + 1
End If
' GYO = GYO + 1
' Cells(GYO, 1).Value = strREC
Loop
MsgBox "aa: " & cnt
Set TS = FSO.opentextfile(cnsFILENAME, ForReading)
' ファイルのEOF(End of File)まで繰り返す
Do Until TS.AtEndOfStream
'改行までをレコードとして読み込む
strREC = TS.ReadLine
GYO = GYO + 1
Cells(GYO, 1).Value = strREC
'リビジョンがあったら、cntをカウントアップ
For i = 0 To cnt
If InStr(strREC, "リビジョン") Then
Cells(GYO, 6).Value = Right(strREC, 2)
Cells(GYO, 7).Value = GYO
ElseIf InStr(strREC, "作者") Then
Cells(GYO - 1, 8).Value = strREC
Cells(GYO - 1, 9).Value = GYO
ElseIf InStr(strREC, "日時") Then
Cells(GYO - 2, 10).Value = strREC
Cells(GYO - 2, 11).Value = GYO
End If
' If InStr(strREC, "作者") Then
'
' Cells(GYO, 8).Value = strREC
' Cells(GYO, 9).Value = GYO
' End If
Next
'行を加算しA列にレコード内容を表示 (先頭は2行目)
Loop
'リビジョンの数を表示
'MsgBox "リビジョンの数:" & cnt
' 指定ファイルをCLOSE
TS.Close
Set TS = Nothing
Set FSO = Nothing
End Sub
set path="F:\_a\mydoc\repo\demo"
for /F "usebackq" %%i in (`dir /s /b %path%` ) do (
echo %%i
echo %%i >> list_demo.txt
)
echo "AAA"
pause
最終更新:2023年10月16日 14:38