DirectoryWatcher.AddDirectory
-----------------------------

Adds a directory to watch.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [DirectoryWatcher](component_DirectoryWatcher.md) | [7.1](newinversion71.md) | ❌ No | ✅ Yes | ❌ No | ✅ Yes, on Windows | ❌ No |

MBS( "DirectoryWatcher.AddDirectory"; Watcher; Path; Recursive; Action ) 

**MBS**( **"DirectoryWatcher.AddDirectory";** /\* Adds a directory to watch. \*/  
**$Watcher**; /\* The watcher reference number. \*/   
**$Path**; /\* The directory path to verify.e.g. "C:\\Users\\Administrator\\Desktop" \*/   
**$Recursive**; /\* Whether to recursively check subdirectories.  
Pass 1 to turn on or 0 to turn off.e.g. 1 \*/   
**$Action**) /\* The changes to monitor.e.g. "Filename¶DirName¶Attributes¶Size¶LastWrite¶LastAccess¶Creation¶Security" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Watcher | The watcher reference number. | $watcher |
| Path | The directory path to verify. | "C:\\Users\\Administrator\\Desktop" |
| Recursive | Whether to recursively check subdirectories.   Pass 1 to turn on or 0 to turn off. | 1 |
| Action | The changes to monitor. | "Filename¶DirName¶Attributes¶Size¶LastWrite¶LastAccess¶Creation¶Security" |

### Result

Returns OK or error.

### Description

Adds a directory to watch.  
With the actions you can define what changes to report.  
  
| Action | Value | Description |
|---|---|---|
| Filename | 1 | Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name. |
| DirName | 2 | Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory. |
| Attributes | 4 | Any attribute change in the watched directory or subtree causes a change notification wait operation to return. |
| Size | 8 | Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. |
| LastWrite | 16 | Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. |
| LastAccess | 32 | Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return. |
| Creation | 64 | Any change to the creation time of files in the watched directory or subtree causes a change notification wait operation to return. |
| Security | 256 | Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return. |

### Examples

Watch for changes in directory:

 MBS ("DirectoryWatcher.AddDirectory"; $Watcher ; Directory Watcher::Directory ; 1; "Filename¶DirName¶Attributes¶Size¶LastWrite¶LastAccess¶Creation¶Security")  
### Example Databases

- [Win Only/Directory Watcher](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/Directory%20Watcher.shtml#2ScriptAnchor_)

This function checks for a license.

Created 5th March 2017 , last changed 26th May 2017

  
[Dictionary.Values](DictionaryValues.md) - [DirectoryWatcher.ChangeCount](DirectoryWatcherChangeCount.md)

[HTML Version](DirectoryWatcherAddDirectory.shtml)