Given a folder in Windows, create a program that watches a folder and notify of changed files inside that folder.
For example, let's assume we ask this program to watch the folder called `c:\webroot\static files`.
For the sake of the examples below, let's also assume that there is a file `c:\webroot\static files\wp-content\upload\Plüsch_rosa_Höschen_für_das_Eichhörnchen.jpeg` which happens to be inside that folder.
We want to know whenever files inside that folder (`c:\webroot\static files` in our example) are created, changed, or deleted, by registering those events inside a directory structure right inside `c:\webroot\static files`, as explained below.
## The changelist folder
The events are registered as lines inside files with particular names.
We call the whole arrangement "a changelist", because at the end of the day, it's just a linear list of changes, sorted from earliest to latest change.
However, we want our software to be able to read recent entries in an inexpensive way, independently of the way the folder and its files are exposed to the network.
Thus, changelists are stored in a format amenable for incremental read, distributed across files under a directory with a special name, `__sc_changelist__`, below the root of the exposed directory.
In our example, this would result in a directory at `c:\webroot\static files\__sc_changelist__`.
We use the 64 bit representation of the [Posix time](https://en.wikipedia.org/wiki/Unix_time), and create hierarchical directories
named after the hex representation of the 64-bit word in big-endian order, with the four higher octets abbreviated *as a single*`0`, and where the second smallest
octet is a file instead of a folder, including all the changes that happen in the 256 seconds it covers.
Here is an example: the changes to the filesystem between between Monday, January 22, 2018 1:45:00 PM and Monday, January 22, 2018 1:50:00 PM would be registered by taking the timestamps of those two dates:
```
1516628700
1516629000
```
converting them to hex and including the padding (to avoid the [Year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem)):
```
0x 00 00 00 00 5a 65 ea dc
0x 00 00 00 00 5a 65 ec 08
```
We abbreviate the first four octets as a single folder named `0` in the filesystem, and
that results in the following files:
```
__sc_changelist__ / 0 / 5a / 65 / ea
__sc_changelist__ / 0 / 5a / 65 / eb
__sc_changelist__ / 0 / 5a / 65 / ec
```
In the list above, the rightmost group of each line is a file: `ea`, `eb` and `ec`.
Notice that the lowest octet is omitted from the combination of directories and file names.
It's OK if files that otherwise would be empty are missing.
In the files themselves (`ea`, `eb` and `ec` in the example above),
each the lines uses one of three syntaxes, all of which we describe using a simple grammar:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.