How do I watch a file for changes?

前端 未结 25 2761
孤街浪徒
孤街浪徒 2020-11-21 07:13

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I\'d like to read the new data in to do some processing on it

相关标签:
25条回答
  • 2020-11-21 08:14

    If you're using windows, create this POLL.CMD file

    @echo off
    :top
    xcopy /m /y %1 %2 | find /v "File(s) copied"
    timeout /T 1 > nul
    goto :top
    

    then you can type "poll dir1 dir2" and it will copy all the files from dir1 to dir2 and check for updates once per second.

    The "find" is optional, just to make the console less noisy.

    This is not recursive. Maybe you could make it recursive using /e on the xcopy.

    0 讨论(0)
提交回复
热议问题