Translate

2011年7月1日金曜日

てすと

Option Explicit
On Error Resume Next
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim LockDirectoryPath, LogFilePath
LockDirectoryPath = FSO.GetAbsolutePathName("lock")
LogFilePath       = FSO.GetAbsolutePathName("log.txt")

'ロックファイル作成
Do
    FSO.CreateFolder(LockDirectoryPath)
    if Err.Number = 0 then Exit Do
    Err.Clear
Loop


'書き込むファイルを作成
if Not FSO.FileExists(LogFilePath) Then
    Do
        Err.Clear
        FSO.CreateTextFile(LogFilePath)
        if Err.Number = 0 then Exit Do
    Loop
    
End If

'ファイルから1行読み取る
Dim File, OneLine
Err.Clear
Set File = FSO.OpenTextFile(LogFilePath, 2, True)
If Err.Number = 0 then
    OneLine = File.ReadLine
    
    if OneLine = "" then
        OneLine = 0
    Else
        OneLine = OneLine + 1
    End If
    
    Err.Clear
    File.Write(OneLine)
    If Err.Number = 0 Then msgbox "書き込みエラー"
    File.Close
End If



Set File = Nothing
Set FSO  = Nothing
On Error Goto 0
msgbox "終了"
単なるめも。後で修正が必要