Files
Share_Li/Init-DeveloperDrive.ps1
2025-12-20 13:25:24 +00:00

37 lines
1.3 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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"
}
foreach ($Source in $Mappings.Keys) {
$Destination = $Mappings[$Source]
# 如果 D 盘目标目录不存在,则创建
if (!(Test-Path $Destination)) {
New-Item -Path $Destination -ItemType Directory -Force | Out-Null
}
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
}