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

相关推荐
shada44 分钟前
CMake指定 MSVC 工具集与 Windows SDK
c++·windows
the3clipse1 小时前
Windows 10 与 Windows 11 视频编解码区别:AV1、HEVC、HDR 与 D3D12 编码支持对比
windows·h.265·hevc·hdr·av1·视频解码·d3d12
郭庆汝1 小时前
(三)MCP+A2A 从0到1构建类Manus多Agent全栈应用
windows
the3clipse2 小时前
MacOS、Linux 与 Windows 视频编解码对比:AV1、HEVC、ProRes 与硬件加速优劣势
linux·windows·macos·hevc·av1·视频解码·硬件解码
明王明王2 小时前
PVE 上用 SPICE:统一连接 Debian、Arch 和 Windows 11 桌面
运维·windows·debian
学逆向的2 小时前
win32消息类型
windows·网络安全·mfc·api·win32
TeamDev2 小时前
JxBrowser 9.5.2 版本发布啦!
java·前端·windows·chromium·混合应用·jxbrowser·浏览器控件
段一凡-华北理工大学13 小时前
大模型应用开发 100 天:Python + LLM 从入门到精通 day26~Prompt 调试与优化——A/B 测试与效果评估
windows·python·大模型·prompt·智能体·提示词工程·高炉智能化
fox_charon14 小时前
Windows 下 CLI 参数的引号陷阱:为什么 --resume 'uuid' 会失败
windows·shell·cmd·cli·引号
染指111015 小时前
128.Agent-LangChain核心组件-中间件-调用模型的时候
人工智能·windows·中间件·langchain·agent