[英]Looping to subfolder batch file repeats same folder
想法是将批处理文件目录中单独文件夹中的所有jpg文件合并到一个没有任何子目录的新文件夹中。 它按预期工作了几个小时,但现在它不断循环复制第一个文件夹的相同文件。 关于真正错误的任何线索?
@echo off
::rmdir /S .\merge
::pause
mkdir .\merge
call :treeProcess
goto :eof
::pause
:treeProcess
rem Do whatever you want here over the files of this subdir, for example:
for %%f in (*.jpg) do (
echo %%f
xcopy .\*.jpg ..\merge\ /Y
)
for /D %%d in (*) do (
cd %%d
call :treeProcess
cd ..
)
exit /b
我得到了一个解决方案,但仍然感到困惑,好像我删除了echo %%G
, echo %%H
, echo back to
.. 代码仍然失败( unexpected at this time
。
@echo off
::SETLOCAL EnableDelayedExpansion
::rmdir /S .\merge
::pause
::mkdir .\merge
dir /b /a-d
cd .
call :treeProcess
goto :eof
pause
:treeProcess
REM rem Do whatever you want here over the files of this subdir, for example:
for %%G in (*.jpg) do (
echo %%G
echo %%H
::echo inside %%H
REM rem xcopy .\*.jpg ..\merge\ /e /Y
xcopy .\%%G ..\merge\ /Y
)
FOR /D %%H in (*20*) do (
cd %%H
rem dir /b /a-d
call :treeProcess
cd ..
echo back to ..
)
REM exit /b
REM :treeProcess
rem Do whatever you want here over the files of this subdir, for example:
REM %%G is a good choice because it does not conflict with any of the pathname format letters (a, d, f, n, p, s, t, x) and provides the longest run of non-conflicting letters for use as implicit parameters.
REM G > H > I > J > K > L > M
REM Format letters are case sensitive, so using a capital letter is also a good way to avoid conflicts %%A rather than %%a.
exit /b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.