You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10下如何移动特定扩展名文件并保留目录结构?

批量整理游戏库CD镜像与文件结构的PowerShell方案

操作步骤与脚本

1. 前置准备

确保以管理员模式启动PowerShell(避免权限限制),并确认D、E分区正常可用。

2. 执行批量处理脚本

将以下代码复制到PowerShell中运行,若你的分区盘符不同,替换代码中的D:\和E:\为实际路径即可:

# 遍历D盘下所有游戏主文件夹(即FullGameName)
Get-ChildItem -Path "D:\" -Directory | ForEach-Object {
    $gameMainDir = $_
    $gameName = $gameMainDir.Name
    
    # --- 整理D盘内的文件结构:将游戏文件移入同名子文件夹 ---
    $targetGameSubDir = Join-Path -Path $gameMainDir.FullName -ChildPath $gameName
    if (-not (Test-Path -Path $targetGameSubDir)) {
        New-Item -Path $targetGameSubDir -ItemType Directory | Out-Null
    }
    # 移动主文件夹内除CD外的所有内容到子文件夹
    Get-ChildItem -Path $gameMainDir.FullName -Exclude "CD" | Move-Item -Destination $targetGameSubDir -Force
    
    # --- 移动CD文件夹到E盘对应路径 ---
    $sourceCDDir = Join-Path -Path $gameMainDir.FullName -ChildPath "CD"
    if (Test-Path -Path $sourceCDDir) {
        $targetGameRootDir = Join-Path -Path "E:\" -ChildPath $gameName
        if (-not (Test-Path -Path $targetGameRootDir)) {
            New-Item -Path $targetGameRootDir -ItemType Directory | Out-Null
        }
        $targetCDDir = Join-Path -Path $targetGameRootDir -ChildPath "CD"
        Move-Item -Path $sourceCDDir -Destination $targetCDDir -Force
    }
}

3. 脚本功能说明

  • 遍历游戏主文件夹:自动识别D盘下所有顶级游戏文件夹(FullGameName)
  • 重组D盘结构:为每个游戏主文件夹创建同名子文件夹,将原主文件夹内除CD外的所有文件/文件夹移入其中,匹配你期望的D盘目录结构
  • 迁移CD镜像:检查每个游戏主文件夹下的CD文件夹,若存在则在E盘创建对应游戏主文件夹,完整迁移CD文件夹及其内的.iso文件,保留原有子结构

注意事项

  • 建议先选取1-2个游戏文件夹测试脚本,确认效果符合预期后再批量执行
  • 若E盘已存在同名游戏主文件夹,脚本会直接将CD文件夹移入;若目标路径已有CD文件夹,-Force参数会覆盖原有内容,如需避免覆盖可移除该参数并提前处理冲突
  • 确保PowerShell有D、E盘的文件读写权限

内容的提问来源于stack exchange,提问作者Ricardo Ramos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 13:23:24