How do I watch a file for changes?

前端 未结 25 2780
孤街浪徒
孤街浪徒 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 07:49

    As you can see in Tim Golden's article, pointed by Horst Gutmann, WIN32 is relatively complex and watches directories, not a single file.

    I'd like to suggest you look into IronPython, which is a .NET python implementation. With IronPython you can use all the .NET functionality - including

    System.IO.FileSystemWatcher
    

    Which handles single files with a simple Event interface.

提交回复
热议问题