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