更新 Init-DeveloperDrive.ps1

This commit is contained in:
2025-12-20 13:34:05 +00:00
parent 399d594024
commit 7cd9a69488

View File

@@ -1,37 +1,25 @@
# 1_Map_Dev_Caches.ps1
$TargetBase = "D:\Data\Symlink_Storage"
# 2_Move_System_Folders.ps1
$D_Doc = "D:\Document"
# 定义映射关系C盘路径 = D盘子路径
$Mappings = @{
"$HOME\.m2" = "$TargetBase\.m2"
"$HOME\.gradle" = "$TargetBase\.gradle"
"$HOME\.npm" = "$TargetBase\npm-cache"
"$env:LOCALAPPDATA\pip\cache" = "$TargetBase\pip-cache"
# 定义注册表键名与 D 盘新路径的对应关系
$Folders = @{
"Desktop" = "$D_Doc\Desktop"
"Personal" = "$D_Doc\Documents"
"{374DE290-123F-4565-9164-39C4925E467B}" = "$D_Doc\Downloads" # Downloads 键名
"My Pictures" = "$D_Doc\Pictures"
}
foreach ($Source in $Mappings.Keys) {
$Destination = $Mappings[$Source]
$RegistryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
# 如果 D 盘目标目录不存在,则创建
if (!(Test-Path $Destination)) {
New-Item -Path $Destination -ItemType Directory -Force | Out-Null
foreach ($Key in $Folders.Keys) {
$NewPath = $Folders[$Key]
# 创建 D 盘目录
if (!(Test-Path $NewPath)) { New-Item -Path $NewPath -ItemType Directory -Force }
# 修改注册表
Set-ItemProperty -Path $RegistryPath -Name $Key -Value $NewPath
Write-Host "[成功] $Key 路径已改为 $NewPath" -ForegroundColor Green
}
if (Test-Path $Source) {
# 如果 C 盘已经是符号链接,跳过
$folder = Get-Item $Source
if ($folder.Attributes -match "ReparsePoint") {
Write-Host "[跳过] $Source 已经是映射状态" -ForegroundColor Yellow
continue
}
# 移动现有文件到 D 盘
Write-Host "[处理] 正在搬移 $Source -> $Destination" -ForegroundColor Cyan
Move-Item -Path "$Source\*" -Destination $Destination -Force -ErrorAction SilentlyContinue
Remove-Item -Path $Source -Recurse -Force
}
# 创建符号链接 (Junction)
New-Item -Path $Source -ItemType Junction -Value $Destination
Write-Host "[成功] 已建立链接: $Source" -ForegroundColor Green
}
Write-Host "提示:请重启电脑或重新启动 Windows 资源管理器以应用更改。" -ForegroundColor Yellow