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

相关推荐
叼烟扛炮9 小时前
[LangChain] 学习笔记(06):突破大模型限制——结构化输出(Structured Output)
windows·笔记·学习·langchain
Thneonl20 小时前
桌宠穿透不是一行 SetWindowLong
windows·程序员
艺杯羹2 天前
Windows原生软件锁设计:从暴力杀进程丢数据到零轮询事件驱动架构
windows·系统架构·开源·开源软件·内存管理·开源协议
csdn_aspnet2 天前
Redis 入门:Windows、Mac安装指南
数据库·windows·redis·缓存·mac
没差c3 天前
winsw将jar、nginx等注册为Windows服务
windows·nginx·jar
光谱SpectrAI3 天前
Claude Code 2.1.318 的隐私模块:4 条命令,拦了 2 条
windows
Hello_Pyhx3 天前
NWinfo 导出 Windows 硬件信息:从 JSON 报告到缺项排查
windows·json
百事牛科技4 天前
Excel的三种密码:防看、防存、防乱改,各管各的
windows·excel
the3clipse5 天前
MPC-HC 下载安装与最佳配置教程:免费开源、轻量无广告、支持 4K 硬解的 Windows 播放器
windows·播放器·安装教程·硬件加速·mpc-hc·字幕设置·lav filters
独隅5 天前
WebStorm Windows 版 React / Next.js 实战替换指南
javascript·windows·webstorm