File Sync

👤 67available 📦 v1.0.1 ⭐ 4.4 ⬇️ 696 下载
🔒 IT运维与安全 免费

📖 技能介绍


name: file-sync description: Bidirectional file synchronization tool using MD5 hash + version history for conflict detection. Use when the user needs to sync files between two directories (e.g., PC ↔ USB), wants to set up a file sync workflow, or asks to sync/merge two folders with conflict detection. Triggers on keywords: sync files, file sync, bidirectional sync, two-way sync, sync.py, merge folders, sync PC and USB. version: 1.0.1 changelog: "1.0.1": "Fixed bug where shutil.copy2 was called without first creating parent directories, causing failures when syncing into nested subdirectories."


file-sync

sync.py is a bidirectional file synchronization tool. It keeps two directories in sync (e.g. PC ↔ USB), detects conflicts using version history, and handles deletions safely via .trash/.

Usage

python sync.py <local_folder> <remote_folder> <device_name>

Arguments: - local_folder — First directory to sync - remote_folder — Second directory to sync - device_name — Label for this device (used in conflict file names, e.g. "PC1", "USB")

Sync direction: The tool is symmetric — either folder can be local or remote.

Sync Rules

7w4.net收录了海量优质技能插件。

Situation Behavior
New file on one side Copy to the other side
Single-side modification Copy updated file to the other side
Concurrent modification (conflict) Both copies → .conflict/, no overwrite
File deleted on one side, kept on other Conflict (both kept in .conflict/)
File deleted on both sides Remove from both, nothing to trash
One side deletes, other side unchanged Delete propagates to the other side via .trash/

Special Directories (auto-ignored)

Files and folders matching these names are excluded from sync: .conflict, .trash, .sync_logs

State & History

State is stored in .sync_state.json in each folder. Each file maintains a history list of MD5 hashes (up to 10 entries). Conflict detection uses history to find a common ancestor: - No common ancestor → conflict - One side unchanged (matches ancestor) → auto-merge - Both sides changed from ancestor → conflict

Conflict Resolution

When a conflict is detected, both versions are copied into local_folder/.conflict/ with names like:

filename_LOCAL_<device>_<timestamp>
filename_REMOTE_<device>_<timestamp>

The original files are left untouched. Manually review and merge, then delete from .conflict/.

Deletion Safety

Deleted files go to .trash/<relpath>.<timestamp> rather than being permanently removed.

Logging

Logs are written to local_folder/.sync_logs/sync_<timestamp>.log, including timestamps, action types (INFO/CONFLICT/TRASH/ERROR), and a summary count.

Workflow Example

# Sync PC1 with USB drive (USB mounted as E:)
python sync.py C:\Users\PC1 E:\ PC1

# Sync back after working on USB
python sync.py E:\ C:\Users\PC1 USB

Bundled Resources

  • scripts/sync.py — The sync script (copy to your project or call directly)
  • references/behaviors.md — Detailed behavior notes, edge cases, and design rationale

🤖 AI 评测

这是一个质量不错的文件同步工具,功能实用且文档齐全。优点是使用简单、能自动检测文件冲突、删除的文件会安全地移到回收站而不是直接删除。缺点是没有充分测试过多人同时使用的场景,容易出问题。整体来说,对于日常在电脑和U盘之间同步文件是够用的,但别同时开两个同步程序。推荐指数:★★★☆☆

📊 多维度评分

适应性4.5
规范性4.3
有效性4.3
可靠性4.1
可信度4.8

📁 包含文件 (4 个)

📄 SKILL.md 3.1 KB
📄 _meta.json 128 B
📄 references/behaviors.md 3.1 KB
📄 scripts/sync.py 9.3 KB