搜索结果

×

搜索结果将在这里显示。

一鍵歸檔(Powershell)

pwsh.exe -nol -c ni archive -Type Directory -Force; mv 2021* -Destination .\archive\,-nol

參數

  • ni 是别名 → New-Item
  • mv 是别名 → Move-Item
  • 2021* 会匹配所有以 2021 开头的文件/文件夹
  • 如果 archive 文件夹已存在,-Force 参数会抑制错误但不覆盖

脚本


# 创建 archive 文件夹(如果不存在)
if (-not (Test-Path -Path "archive")) {
    New-Item -Path "archive" -ItemType Directory | Out-Null
    Write-Host "✅ 已创建 archive 文件夹" -ForegroundColor Green
}

# 移动所有 2021 开头的文件/文件夹
$files = Get-Item -Path "2021*" -ErrorAction SilentlyContinue

if ($files) {
    $files | Move-Item -Destination ".\archive\" -Force
    Write-Host "✅ 已移动 $($files.Count) 个项目到 archive\" -ForegroundColor Green
} else {
    Write-Host "⚠️ 未找到以 2021 开头的文件或文件夹" -ForegroundColor Yellow
}
pwsh.exe -NoLogo -Command "if (-not (Test-Path 'archive')) { New-Item 'archive' -ItemType Directory | Out-Null }; Get-Item '2021*' | Move-Item -Destination '.\archive\' -ErrorAction SilentlyContinue; Write-Host '完成'"
发布时间: