Windows系统递归将文件夹及其子文件夹下所有照片拷贝到新指定文件夹脚本

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 运行"

相关推荐
问简2 小时前
【共享盘】ubuntu、windows
linux·windows·ubuntu
公子小六3 小时前
基于.NET的Windows窗体编程之WinForms图像控件
windows·microsoft·c#·.net·winforms
狂热开发者4 小时前
用 Typeoff 把会后口述整理成 Markdown 决策记录
人工智能·windows·macos·ios·安卓
何中应4 小时前
Windows7 虚拟机如何传文件
windows·vmware·虚拟机
ofoxcoding4 小时前
Codex Computer Use 完整指南:AI 自动操控 Mac 与 Windows 桌面实战详解
人工智能·windows·macos·ai
Nontee5 小时前
Set 这个东西,跟我一开始想的不太一样
java·linux·windows·microsoft
XUHUOJUN6 小时前
Windows Server 2025 Stretch Cluster 架构详解
windows·microsoft·azure local
zhou135284822676 小时前
Windows 配置 WSL (Ubuntu) 环境完整指南
linux·windows·ubuntu
han_hanker6 小时前
sql语法 MyBatis <foreach> 标签详解
windows·sql·mybatis
XUHUOJUN7 小时前
Windows Server 2025 RAC vs Stretch Cluster 技术定位
windows·microsoft·azure local