简体   繁体   中英

Looping to subfolder batch file repeats same folder

Idea was to merge all jpg files in separate folders in the directory of the batch files to a new folder without any subdirectories. It worked as expected for a few hours but now it keeps looping copying the same files of the first folder again and again. Any clue on what is really wrong?

@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

I got a solution but still confused as if I remove echo %%G , echo %%H , echo back to .. the code still fails saying ( 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM