0

我有一个名为 abc.txt 的文件,想要根据修改的日期和时间连续读取

我试过这样,但我想根据日期和时间的变化循环检查文件。

Global $file
func filess()
$search = FileFindFirstFile("abc.txt")
if @error Then
    MsgBox(0, "error", "failed to find first file")
    Exit
EndIf
While -1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    ConsoleWrite("File:" & $file & @CRLF)

    $time = FileGetTime($file,0)
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
     MsgBox(0, "Modify date and time of file", $dmyyyy)
    if @error Then
        ConsoleWrite("Error getting time from " & $file & @CRLF)

    EndIf


WEnd
Return $file
EndFunc
; Close the search handle
$mss=filess()
4

2 回答 2

0

你的剧本中有很多东西是错误的。试试这个:

$myfile = "abc.txt"

$OldFileTime = filess($myfile)

while 1
sleep(2000)
if $OldFileTime <> filess($myfile) then MsgBox(0, "Info","File " & $myfile & " has changed!")

wend


func filess($file)

    $time = FileGetTime($file,0)
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
    if @error Then ConsoleWrite("Error getting time from " & $file & @CRLF)

Return $dmyyyy

EndFunc
于 2013-10-16T15:26:19.220 回答
0
$name = "c:\my_file.txt"

; set Monitor File Modification
$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
    $strComputer & "\root\cimv2")

$colMonitoredEvents = $objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " _
    & "TargetInstance ISA 'CIM_DataFile' and " _
        & 'TargetInstance.Name="'&$name & '"')

; Main Loop
While 1
    $objLatestEvent = $colMonitoredEvents.NextEvent
    your_func()
WEnd
于 2013-11-03T01:41:59.210 回答