# c-migrate **Repository Path**: xiaobaer/c-migrate ## Basic Information - **Project Name**: c-migrate - **Description**: 为 C 盘空间不足的 Windows 用户精心打造。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2026-07-21 - **Last Updated**: 2026-07-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # C-Migrate / C盘迁移工具

A lightweight Windows tool to migrate C drive folders to another drive using Junction.
一款轻量级 Windows 工具,用于将 C 盘文件夹迁移到其他磁盘,并通过目录联接(Junction)保持原路径可用。

Platform Go Wails License

--- ## 📖 Table of Contents / 目录 - [Introduction / 简介](#introduction--简介) - [Features / 功能特性](#features--功能特性) - [Screenshots / 界面截图](#screenshots--界面截图) - [How It Works / 工作原理](#how-it-works--工作原理) - [Build / 编译](#build--编译) - [Development Mode / 开发模式](#development-mode--开发模式) - [Production Mode / 生产模式](#production-mode--生产模式) - [Usage / 使用方法](#usage--使用方法) - [Project Structure / 项目结构](#project-structure--项目结构) - [Technical Highlights / 技术亮点](#technical-highlights--技术亮点) - [Safety / 安全性](#safety--安全性) - [License / 开源协议](#license--开源协议) --- ## Introduction / 简介 **English:** C-Migrate is a Windows desktop application that helps you free up space on your C drive by migrating large folders to another drive (e.g., D:), while keeping the original paths fully functional through Windows Directory Junctions (symbolic links). Typical use cases: - Move `Users\\Documents`, `Downloads`, `Desktop` to D drive - Move large game folders or developer toolchains (`Node_modules`, `.gradle`, etc.) - Move `ProgramData` subfolders that consume too much space - Any folder on C drive that is safe to relocate **中文:** C盘迁移工具是一款 Windows 桌面应用,帮助你将 C 盘上的大文件夹迁移到其他磁盘(如 D 盘),同时通过 Windows 目录联接(Junction)保持原路径完全可用,程序不会感知到任何变化。 典型使用场景: - 迁移 `Users\<用户名>\Documents`、`Downloads`、`Desktop` 到 D 盘 - 迁移大型游戏文件夹或开发工具链(`Node_modules`、`.gradle` 等) - 迁移占用空间过大的 `ProgramData` 子目录 - C 盘上任何可以安全移动的位置 --- ## Features / 功能特性 | Feature / 功能 | Description / 描述 | |---|---| | **Concurrent Scanning** / 并发扫描 | Scans all top-level folders concurrently using goroutines, significantly faster than sequential scanning. 使用 goroutine 并发扫描所有一级子文件夹,速度远超串行扫描。 | | **Sub-file Lock Detection** / 子文件占用检测 | Not only checks if the folder itself is locked, but also samples recently modified sub-files for occupancy. 不仅检测文件夹本身是否被占用,还采样检测最近修改的子文件是否被占用。 | | **Size & Activity Display** / 大小与活动时间 | Shows folder size, last modified file, and last activity time, sorted by size descending. 显示文件夹大小、最后修改文件、最后活动时间,按大小降序排列。 | | **Robocopy Migration** / Robocopy 迁移 | Uses Windows `robocopy` with multi-threading (`/MT:8`), backup mode (`/ZB`), and resume support. 使用 Windows `robocopy` 多线程复制(`/MT:8`),支持备份模式(`/ZB`)和断点续传。 | | **Integrity Verification** / 完整性验证 | After copying, verifies file count and total size match between source and destination (±0.5% tolerance). 复制后验证源目录和目标目录的文件数量、总大小是否一致(允许 0.5% 误差)。 | | **Junction Creation** / 目录联接 | Creates a Windows Directory Junction at the original path pointing to the new location. 在原路径创建 Windows 目录联接(Junction),指向新位置。 | | **Junction Verification** / 联接验证 | Verifies the Junction works correctly by reading its contents before cleanup. 在清理前验证 Junction 能正常读取目录内容。 | | **Auto Cleanup** / 自动清理 | Automatically removes the backup folder after successful migration. 迁移成功后自动删除备份目录。 | | **Rollback on Failure** / 失败回滚 | Any step fails → automatically rolls back to original state (restore folder, delete incomplete copy). 任一步骤失败 → 自动回滚到原始状态(恢复文件夹、删除不完整的复制)。 | | **Real-time Progress** / 实时进度 | Shows live progress percentage during robocopy operation. robocopy 执行期间实时显示复制进度百分比。 | --- ## Screenshots / 界面截图

Main Interface / 主界面
Main Interface / 主界面

Migration Progress / 迁移进度
Migration Progress / 迁移进度

--- ## How It Works / 工作原理 ``` C:\Users\Alice\Documents D:\Migrate\Documents │ ▲ │ ┌──────────────┐ │ └───►│ robocopy │────────────┘ │ /E /COPYALL │ │ /ZB /MT:8 │ └──────────────┘ │ ▼ C:\Users\Alice\Documents-BAK-20240611-112345 │ ┌────────────┘ ▼ C:\Users\Alice\Documents [Junction] ──────► D:\Migrate\Documents ``` **Migration Flow / 迁移流程:** 1. **Fix Permissions** — `takeown` + `icacls` to ensure full access 2. **Robocopy** — Multi-threaded copy with backup semantics 3. **Verify Integrity** — Compare file count & total size (source vs destination) 4. **Rename Original** — Original folder renamed to `*-BAK-*` 5. **Create Junction** — `mklink /J` creates a Directory Junction at original path 6. **Verify Junction** — Ensure the Junction is readable 7. **Delete Backup** — Remove the backup folder after confirmation **Rollback Strategy / 回滚策略:** | Failure Point / 失败点 | Rollback Action / 回滚动作 | |---|---| | Robocopy fails (exit ≥ 8) | Delete incomplete destination / 删除不完整的目标目录 | | Integrity verification fails | Delete destination / 删除目标目录 | | Rename original fails | Delete destination / 删除目标目录 | | Junction creation fails | Restore original name + delete destination / 恢复原名 + 删除目标 | | Junction verification fails | Remove Junction + restore original + delete destination / 删除联接 + 恢复原名 + 删除目标 | | Backup deletion fails | Warning only, migration is successful / 仅警告,迁移已成功 | --- ## Build / 编译 ### Prerequisites / 前置条件 - [Go](https://golang.org/dl/) 1.21+ - [Wails CLI](https://wails.io/docs/gettingstarted/installation) v2.9.1+ - Windows 10/11 (Administrator privileges required for migration / 迁移需要管理员权限) ### Development Mode / 开发模式 ```bash go build -tags dev -gcflags "all=-N -l" ``` > `-gcflags "all=-N -l"` disables optimization and inlining for debugging. > `-gcflags "all=-N -l"` 禁用优化和内联,便于调试。 ### Production Mode / 生产模式 ```bash go build -tags desktop,production -ldflags "-w -s -H windowsgui" ``` > `-w -s` strips debug info to reduce binary size. > `-H windowsgui` hides the console window (GUI app). > `-w -s` 去除调试信息减小体积,`-H windowsgui` 隐藏控制台窗口。 --- ## Usage / 使用方法 1. **Run as Administrator** / 右键 → 以管理员身份运行(迁移操作需要管理员权限) 2. **Select Source Directory** / 选择源目录:C 盘上需要分析的父目录(如 `C:\Users\Alice`) 3. **Select Destination Directory** / 选择目标目录:D 盘上的一个空文件夹(如 `D:\Migrate`) 4. **Click "Scan"** / 点击"扫描文件夹":分析所有子文件夹的大小和占用状态 5. **Click "Migrate"** / 点击"迁移":程序会自动完成复制 → 验证 → 备份 → 建 Junction → 删备份 > ⚠️ **Warning / 警告**: Do NOT migrate system-critical folders like `C:\Windows`, `C:\Program Files`, or actively running application directories. Migration failures may cause software to malfunction. > 请勿迁移系统关键目录(如 `C:\Windows`、`C:\Program Files`)或正在运行的程序目录,迁移失败可能导致软件无法正常工作。 --- ## Project Structure / 项目结构 ``` c-migrate/ ├── app.go # Wails app binding / Wails 应用绑定 ├── main.go # Entry point / 程序入口 ├── go.mod # Go module / Go 模块定义 ├── frontend/ │ ├── index.html # Main UI / 主界面 │ ├── style.css # Styles / 样式 │ └── app.js # Frontend logic / 前端逻辑 ├── tool/ │ ├── scanner.go # Concurrent folder scanner / 并发文件夹扫描 │ ├── locker.go # File lock detection (Windows) / 文件占用检测 │ ├── migrator.go # Migration logic / 迁移逻辑 │ └── logger.go # File logging / 文件日志 ├── ui/ │ ├── directory_dialog_windows.go # Windows directory dialog / Windows 目录对话框 │ └── directory_dialog_other.go # Fallback for other OS / 其他系统回退 └── logs/ # Runtime logs / 运行日志 ``` --- ## Technical Highlights / 技术亮点 ### Backend / 后端 (Go) | Technology / 技术 | Purpose / 用途 | |---|---| | **Wails v2** | Cross-platform desktop app framework (Go backend + HTML frontend) / 跨平台桌面应用框架 | | **Goroutines + Semaphore** | Concurrent scanning with controlled parallelism (4~16 workers) / 并发扫描,限制并发数避免句柄耗尽 | | **Sampling Lock Detection** | Samples 20 most-recently-modified sub-files per folder for lock detection / 每个文件夹采样 20 个最近修改的子文件检测占用 | | **Robocopy Integration** | Windows native multi-threaded file copy with backup semantics / Windows 原生多线程复制,支持备份模式 | | **Integrity Verification** | `filepath.WalkDir` + file count & size comparison / 遍历对比文件数量和总大小 | | **Junction Management** | `mklink /J` for creation, `rmdir` for safe deletion (won't delete target content) / `mklink /J` 创建联接,`rmdir` 安全删除(不会删除目标内容) | | **Defensive Programming** | `recover()` in multiple places to prevent crashes from Windows API panics / 多处 `recover()` 防止 Windows API panic 导致程序崩溃 | ### Frontend / 前端 | Technology / 技术 | Purpose / 用途 | |---|---| | **Vanilla HTML/CSS/JS** | No frontend framework dependency, lightweight / 无前端框架依赖,轻量级 | | **Wails Runtime Events** | `runtime.EventsEmit` / `EventsOn` for real-time log streaming / 实时日志流推送 | | **Responsive Layout** | CSS Grid sidebar + main table layout / CSS Grid 侧边栏 + 主表格布局 | --- ## Safety / 安全性 - **Never deletes original data before verification** — Original folder is only renamed to backup after copy integrity is verified. - **Automatic rollback** — Any failure triggers automatic cleanup to restore the original state. - **Administrator-only** — The app checks for admin privileges at startup and exits if not elevated. - **Backup preserved on failure** — If migration fails, the original folder remains intact (either at original path or as `*-BAK-*`). - **验证通过前绝不删除原始数据** — 只有在复制完整性验证通过后,才会将原文件夹重命名为备份。 - **自动回滚** — 任何步骤失败都会自动清理并恢复到原始状态。 - **仅管理员运行** — 程序启动时检查管理员权限,非管理员直接退出。 - **失败时保留备份** — 如果迁移失败,原始文件夹保持完整(在原位置或以 `*-BAK-*` 形式存在)。 --- ## License / 开源协议 [MIT License](LICENSE) ``` Copyright (c) 2024 c-migrate authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ``` ---

Made with ❤️ for Windows users running out of C drive space.
为 C 盘空间不足的 Windows 用户精心打造。