Python multithreaded monitoring specified directory

Source: Internet
Author: User

ImportWin32fileImportTempfileImportThreadingImportWin32conImportOsdirs=["c:\\windows\\temp", Tempfile.gettempdir ()]defStart_monitor (path_to_watch): H_directory=Win32file. CreateFile (Path_to_watch, Win32con. Generic_read, Win32con. File_share_delete|win32con. file_share_read|Win32con. File_share_write, None, Win32con. Open_existing, Win32con. File_flag_backup_semantics, None) whileTrue:Try: Results= Win32file. READDIRECTORYCHANGESW (h_directory,1024, True, 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) forAction, filenameinchResults:PrintActionPrintfilenameexcept:            Pass forPathinchDirs:monitor_thread= Threading. Thread (target=start_monitor,args=(path,)) Monitor_thread.start ()

Python multithreaded monitoring Specifies the directory, the main function is

Win32file. READDIRECTORYCHANGESW Monitoring Directory Changes

READDIRECTORYCHANGESW (handle, size, Bwatchsubtree, Dwnotifyfilter , overlapped)

Retrieves information describing the changes occurring within a directory.

Parameters

Handle : Pyhandle

Handle to the directory to be monitored. This directory must is opened with the File_list_directory access right.

size : int

Size of the buffer to allocate for the results.

bwatchsubtree : int

Specifies whether the READDIRECTORYCHANGESW function would monitor the directory or the directory tree. If TRUE is specified, the function monitors the directory tree rooted at the specified directory. If FALSE is specified, the function monitors only the directory specified by the hdirectory parameter.

dwnotifyfilter : int

Specifies filter criteria the function checks to determine if the wait operation have completed. This parameter can is one or more of the file_notify_change_* values.

overlapped=none : pyoverlapped

An overlapped object. The directory must also is opened with file_flag_overlapped.

Python multithreaded monitoring specified directory

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.