このディレクトリ構造があります:
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