В пакетном файле Windows есть способ пересечения иерархии папок/подпапок, выполняющих некоторые действия над каждым файлом?Как перемещаться по дереву/поддеревьям в пакетном файле Windows?
15
A
ответ
13
Да, вы можете сделать это с помощью команды for
с переключателем /r
, например .:
for /r %%f in (*) do echo %%f
Смотрите также this question для примера.
4
Вы можете использовать команду FOR
с помощью переключателя /r
, в результате чего дерево каталогов будет выполняться независимо от того, что вы указываете в инструкции DO
для каждой директории. Там вы можете вставить еще один оператор FOR
, используя dir /b *.*
в блоке SET
.
1
К счастью, у меня есть аналогичная цель в отношении этой темы. Я считаю, что ИНСТРУКЦИЯ
dir /b /s /ad *.* [enter]
будет производить дерево каталогов в результате
complete_path\dir_01_lev_01
complete_path\dir_02_lev_01
complete_path\dir_03_lev_01
complete_path\dir_01_lev_01\dir_11_lev_02
complete_path\dir_01_lev_01\dir_12_lev_02
complete_path\dir_02_lev_01\dir_13_lev_02
complete_path\dir_02_lev_01\dir_14_lev_02
complete_path\dir_02_lev_01\dir_15_lev_02
complete_path\dir_03_lev_01\dir_16_lev_02
Но я хочу привести ниже
complete_path\dir_01_lev_01
complete_path\dir_01_lev_01\dir_11_lev_02
complete_path\dir_01_lev_01\dir_12_lev_02
complete_path\dir_02_lev_01
complete_path\dir_02_lev_01\dir_13_lev_02
complete_path\dir_02_lev_01\dir_14_lev_02
complete_path\dir_02_lev_01\dir_15_lev_02
complete_path\dir_03_lev_01
complete_path\dir_03_lev_01\dir_16_lev_02
Итак, это SCRIPT Рождается :)
@echo off
rem
rem ::: My name is Tree-Folder-8-Level.cmd
rem
setlocal
rem ::: Put started PATH here
set i01=complete_path
for /f "delims=" %%a in ('dir "%i01%" /ad /on /b') do call :p001 "%%a"
endlocal
goto :eof
:p001
rem ::: Display 1st LEVEL of started PATH
echo %~1
for /f "delims=" %%b in ('dir "%i01%\%~1" /ad /on /b') do call :p002 "%~1\%%b"
goto :eof
:p002
rem ::: Display 2nd LEVEL of started PATH
echo %~1
for /f "delims=" %%c in ('dir "%i01%\%~1" /ad /on /b') do call :p003 "%~1\%%c"
goto :eof
:p003
rem ::: Display 3rd LEVEL of started PATH
echo %~1
for /f "delims=" %%d in ('dir "%i01%\%~1" /ad /on /b') do call :p004 "%~1\%%d"
goto :eof
:p004
rem ::: Display 4th LEVEL of started PATH
echo %~1
for /f "delims=" %%e in ('dir "%i01%\%~1" /ad /on /b') do call :p005 "%~1\%%e"
goto :eof
:p005
rem ::: Display 5th LEVEL of started PATH
echo %~1
for /f "delims=" %%f in ('dir "%i01%\%~1" /ad /on /b') do call :p006 "%~1\%%f"
goto :eof
:p006
rem ::: Display 6th LEVEL of started PATH
echo %~1
for /f "delims=" %%g in ('dir "%i01%\%~1" /ad /on /b') do call :p007 "%~1\%%g"
goto :eof
:p007
rem ::: Display 7th LEVEL of started PATH
rem ::: and 8th LEVEL of started PATH
echo %~1
for /f "delims=" %%h in ('dir "%i01%\%~1" /ad /on /b') do echo %~1\%%h
goto :eof
Яркие идеи - welco меня. :)
0
dir /b /s /ad *.* | sort
Это должно дать те же результаты, независимо от глубины пути