Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== WATCHDIR method ====== ==== Description ==== This method allows you to monitor the contents of one or more directories on the system and be notified of any changes occurring within them. Its API is quite simple and takes up to three arguments: - The name of the directory to watch (required). - An optional boolean flag denoting if you wish to include sub-directories (defaults to FALSE$). - An optional set of bit-flags detailing the kind of changes you are interested in. By default WATCHDIR notifies you of file creation, changes to the name, and changes to the "Last-Write" time. When a change occurs the FILESYSTEM object raises a [[changed_event|CHANGED]] event to notify you of the fact. As with any other OI window or control you can write your own FILESYSTEM CHANGED event handler to respond to this - note that this is per application, not per window. Like the standard [[changed_event|CHANGED]] event the relevant change information is passed in the "New Data" argument - in this case "NewData" contains a dynamic array with two fields: <code> <1> The name and path of the file being changed <2> A code specifying the type of change </code> Technical note: The WATCHDIR method is based on the underlying ReadDirectoryChangesW Windows API function, details of which can be found [[http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v%3dvs.85).aspx|HERE]]. ==== Applies To ==== FILESYSTEM object ==== Example ==== <code> $insert ms_Win_FileNotify_Equates // Only watch for files being created in the specified dir ... watchFlags = FILE_NOTIFY_CHANGE_CREATION$ bIncludeSubDirs = FALSE$ call exec_Method( "FILESYSTEM", "WATCHDIR", "c:\temp\incoming", bIncludeSubDirs, watchFlags ) Example FILESYSTEM CHANGED event: $insert ms_Win_FileNotify_Equates changeFile = newData<1> changeCode = newData<2> info = "" begin case case ( changeCode = FILE_ACTION_ADDED$ ) info = "Added" case ( changeCode = FILE_ACTION_REMOVED$ ) info = "Deleted" case ( changeCode = FILE_ACTION_MODIFIED$ ) info = "Modified" case ( changeCode = FILE_ACTION_RENAMED_OLD_NAME$ ) info = "Renamed From" case ( changeCode = FILE_ACTION_RENAMED_NEW_NAME$ ) info = "Renamed To" end case call send_Info( info : " ": changeFile ) </code> guides/programming/programmers_reference_manual/watchdir.txt Last modified: 2024/06/19 20:20by 127.0.0.1