脚本使用命令提示符检查文件夹是否为空,然后创建子文件夹

脚本使用命令提示符检查文件夹是否为空,然后创建子文件夹

我正在尝试为父文件夹的每个子文件夹生成 3 个文件夹。如果子文件夹为空,我只需要生成这 3 个文件夹。

我有一个运行良好的脚本,但我在检查是否为 nul 时遇到了困难:

@echo off
setlocal
for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do (
rem enter the directory
pushd %%a
echo In Directory: %%a
#stuck here. if folder is empty { 
md "Folder 1"
md "Folder 2"
md "Folder 3"
#}
rem leave the directory
popd
)
endlocal

答案1

@echo off && setlocal enabledelayedexpansion

2>nul cd /d "C:\Full\Path\To\Root\Target\Foder" || exit /b
set "_cnt=0" && set "_dir=md "Folder 1" "Folder 2" "Folder 3""

for /r "%cd%" /d %%i in (*)do %__AppDir__%tree.exe /a "%%~dpnxi" | find "\-" 1>nul || 2>nul =;(
     1>nul %__AppDir__%where.exe "%%~dpnxi:*.*" || =;( set /a "_cnt+=1"
         call set "_!_cnt!=%%~fi" && echo\In Directory: "%%~fi"
        );=
    );=

for /L %%L in (1,1,!_cnt!)do cd /d "!_%%~L!" && call !_dir! && =;(
     dir /a:d /b /s "!_%%~L!" | %__AppDir__%findstr.exe /e "Folder.1 Folder.2 Folder.3"
    );=
    
%__AppDir__%timeout.exe /t 5 & endlocal

相关内容