bash
# 保存为 copy_photos.ps1
# 源文件夹
$source = "E:\yuan"
# 目标文件夹
$dest = "E:\test"
# 文件类型
$extensions = "*.jpg", "*.jpeg", "*.png", "*.gif", "*.bmp", "*.tiff", "*.webp", "*.heic"
# 如果目标文件夹不存在,则创建目标目录
if (!(Test-Path $dest)) { New-Item -ItemType Directory -Path $dest }
# 递归获取所有图片并复制(自动重命名冲突文件)
Get-ChildItem -Path $source -Recurse -Include $extensions | ForEach-Object {
$target = Join-Path $dest $_.Name
$counter = 1
while (Test-Path $target) {
$target = Join-Path $dest ($_.BaseName + "_$counter" + $_.Extension)
$counter++
}
Copy-Item $_.FullName $target
Write-Host "已复制: $($_.FullName)"
}
Write-Host "`n复制完成!" -ForegroundColor Green
Pause
将上述代码保存为 copy_photos.ps1,保存编码为ANSI
右键 → "使用 PowerShell 运行"