Files
Share_Li/Init-DeveloperDrive.ps1

37 lines
1.3 KiB
PowerShell
Raw Normal View History

2025-12-20 13:25:24 +00:00
# 1_Map_Dev_Caches.ps1
$TargetBase = "D:\Data\Symlink_Storage"
# 定义映射关系C盘路径 = D盘子路径
$Mappings = @{
"$HOME\.m2" = "$TargetBase\.m2"
"$HOME\.gradle" = "$TargetBase\.gradle"
"$HOME\.npm" = "$TargetBase\npm-cache"
"$env:LOCALAPPDATA\pip\cache" = "$TargetBase\pip-cache"
2025-12-20 13:14:39 +00:00
}
2025-12-20 13:25:24 +00:00
foreach ($Source in $Mappings.Keys) {
$Destination = $Mappings[$Source]
2025-12-20 13:14:39 +00:00
2025-12-20 13:25:24 +00:00
# 如果 D 盘目标目录不存在,则创建
if (!(Test-Path $Destination)) {
New-Item -Path $Destination -ItemType Directory -Force | Out-Null
2025-12-20 13:14:39 +00:00
}
2025-12-20 13:25:24 +00:00
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
}
2025-12-20 13:14:39 +00:00
2025-12-20 13:25:24 +00:00
# 创建符号链接 (Junction)
New-Item -Path $Source -ItemType Junction -Value $Destination
Write-Host "[成功] 已建立链接: $Source" -ForegroundColor Green
}