Files
unc-file-watcher/README.md
T

121 lines
3.2 KiB
Markdown

# UNC File Watcher
This project is a Go-based local web console for watching files in UNC paths and copying or moving them to local directories.
After build, the program is a single `exe`. The target machine does not need Go installed.
## Features
The program supports two rule types at the same time:
- Archive rule
Watches `.tar.gz`
Copies or moves files to a `zip` directory
Skips when the `zip` directory already has a file with the same name
Skips when the `unzip` directory already has an extracted folder with the same name
In `move` mode, if the existing archive or extracted folder is verified as the same content, the source file is removed
- Generic file rule
Watches other file types by extension list
Only needs `UNC source path + local target path`
Does not use `unzip`
Supports two dedupe modes
In `move` mode, duplicate files are removed from the source only after hash verification
## Generic File Dedupe
The generic file rule supports these dedupe modes:
- `Same name and same size`
This is the default mode
If the target directory already has a file with the same name and the same size, the file is skipped
If the target directory already has a file with the same name but a different size, it is treated as a conflict and skipped without overwrite
In `move` mode, the program still verifies SHA-256 before deleting the source duplicate
- `Same name and same hash`
When the target directory already has a file with the same name, the program computes SHA-256 for source and target
If the hashes match, the file is skipped
If the hashes do not match, it is treated as a conflict and skipped without overwrite
## Stable File Detection
To avoid processing a file while another service is still writing it in the UNC path, the program checks both conditions:
- `size + modified time` stay unchanged across multiple scans
- the last modified time is older than `stable_for`
Suggested starting values:
```text
scan interval: 15s
stable_for: 1m
stable_scans: 3
```
## Build
```powershell
go build -o unc-file-watcher.exe .
```
## Run
```powershell
.\unc-file-watcher.exe
```
Default listen address:
```text
http://127.0.0.1:18080
```
To change the port:
```powershell
.\unc-file-watcher.exe -listen 127.0.0.1:19090
```
## Web UI Settings
### Archive Rule
- Enable archive rule
- Archive UNC source path
- Zip path
- Unzip path
### Generic File Rule
- Enable generic file rule
- Generic file UNC source path
- Local target path
- Extension list, for example `.csv,.txt,.pdf`
- Dedupe mode
### Shared Settings
- Scan interval
- Stable duration
- Stable scan count
- Transfer mode: `copy` or `move`
- Recursive scan
## Local Settings File
The web UI saves settings automatically next to the executable:
```text
unc-file-watcher-settings.json
```
When you open the page again, the last saved settings are loaded automatically.
## Runtime Notes
- In `copy` mode, source files remain in the UNC path
- In `move` mode, the program copies first and then removes the source file
- In `move` mode, if a duplicate is detected, the source file is removed only after hash/content verification succeeds
- The generic file rule never overwrites an existing target file when a conflict is detected
- The archive rule only handles `.tar.gz`