Python monitors file changes under Windows

Source: Internet
Author: User


It is convenient to use Python to monitor file system changes under Windows. The example code is as follows, very simple, not much to say.


Import Osimport Win32fileimport win32conactions = {1: "Created", 2: "Deleted", 3: "Updated", 4: "Renamed from som Ething ", 5:" Renamed to something "}file_list_directory = Win32con. Generic_read | Win32con. Generic_writepath_to_watch = "." Hdir = Win32file. CreateFile (Path_to_watch, File_list_directory, Win32con. File_share_read | Win32con. File_share_write, None, Win32con. Open_existing, Win32con. File_flag_backup_semantics, None) if __name__ = = ' __main__ ': Print ("123") while 1:print ("321") result s = win32file. READDIRECTORYCHANGESW (Hdir, #handle: Handle to the directory of Be Monito Red.                                               This directory must is opened with the File_list_directory access right.                                               1024x768, #size: Size of the buffer to allocate for the results. True, #bWatchSubtree: Specifies whether the READDIRECTORYCHANGESW function would monitor the directOry or the directory tree. Win32con.                                                File_notify_change_file_name | Win32con.                                                File_notify_change_dir_name | Win32con.                                                File_notify_change_attributes | Win32con.                                                File_notify_change_size | Win32con.                                                File_notify_change_last_write | Win32con.                                               File_notify_change_security, None, None) for the action, file in results:full_filename = Os.path.join (path_to_watch, file) pr Int (Full_filename, actions.get (Action, "Unknown"))




Related Reference Links:

Http://docs.activestate.com/activepython/2.4/pywin32/win32file__ReadDirectoryChangesW_meth.html

Http://docs.activestate.com/activepython/2.5/pywin32/win32file__CreateFile_meth.html

Python monitors file changes under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.