【发布时间】:2013-02-11 12:07:31
【问题描述】:
有这样的目录结构:
Dir1
--Dir2
--File1
--File2
--Dir3
--File3
--File4
--File5
现在我想使用批处理文件将子目录 (Dir2, Dir3) 中的所有文件复制到父目录 Dir1。 我想出了下面的代码,但它不能完美地工作。我得到以下输出 -
Directory2 --It has 4 files all together
Invalid number of parameters
Invalid number of parameters
Does E:\Directory1\Copy\File1.dat specify a file name -- And only this file gets copied
or directory name on the target
(F = file, D = directory)?
代码 -
@echo off
call :treeProcess
Pause
goto :eof
:treeProcess
rem Do whatever you want here over the files of this subdir, for example:
for /D %%d in (*) do (
echo %%d
cd %%d
for %%f in (*) do xcopy %%f E:\Movies\Copy\%%f
call :treeProcess
cd ..
)
exit /b
【问题讨论】:
-
我主要使用一行命令... Dir1>XCOPY * 。 * /s 目录1
-
我猜你是用这个stackoverflow.com/a/8398621作为你的起点。
标签: recursion batch-file xcopy