批处理文件以递归方式将单个子目录从多个父目录移动到另一个定义的单个目录

时间:2013-04-17 17:45:24

标签: batch-file windows-7 move file-processing

如果这个标题不够混淆......希望我想要做的事情要简单易懂。

Windows 7以防万一需要说。

我在我正在处理的文件夹中有多个目录;

C:\WorkingDir\1
C:\WorkingDir\2
C:\WorkingDir\3
and so on

在每个文件夹(1,2,3等)中都有一个子目录,没有其他文件或文件夹;

C:\WorkingDir\1\5E04AB
C:\WorkingDir\2\4F07FC
C:\WorkingDir\3\9DA04F

我需要将父文件夹中的每个子目录移动到新文件夹中;

C:\NewFolder\5E04AB
C:\NewFolder\4F07FC
C:\NewFolder\9DA04F

就是这样!我认为它可能很简单,但我不能围绕变量或更好的资源解释如何使用它们。如果有的话,我不会使用批处理文件,所以我很抱歉这个呼救声。希望有更多知识渊博的人有一个简单的解释,可以帮助我: - )

我发现了这个:http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

但是有人可以将我链接到一个资源,我可以在其中了解有关批量变量和参数的更多信息以供将来参考吗?

谢谢谢谢谢谢

更新

@endoro 感谢您的答复。第一次尝试运行代码时,一定有用户错误。它工作正常,一切都很好!非常感谢你!

更新2 运行User1贡献的代码后,它将创建我的NewFolder目录,但不会复制任何内容。它仍然是空的。这是运行它时DOS中的一些重复输出:

C:\WorkingDir>(
set fldr2=C:\WorkingDir\1\5E04AB
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\2\4F07FC
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\3\9DA04F
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.`

2 个答案:

答案 0 :(得分:0)

请查看输出并删除echo,如果可以:

@echo off &setlocal 
set "workingdir=WorkingDir"
md "C:\NewFolder" 2>nul

pushd "%workingdir%"
cd
for /d %%i in (*) do for /d %%j in ("%%~i\*") do echo move "%%~fj" "C:\NewFolder\%%~nxj"
popd

答案 1 :(得分:0)

我无法对此进行测试,但是:

@echo off
setlocal EnableDelayedExpansion
md "c:\NewFolder\"
cd "C:\WorkingDir\"
for /D /r %%a in ("*") do (
    set fld1=%%a
    cd "%fld1%"
    for /D /r %%b in ("*") do (
        set fld2=%%b
        move "c:\WorkingDir\%fld1%\%fld2%" "C:\NewFolder\%fld2%"
        )
    )

批量的好资源:

http://ss64.com/nt/