批处理判断当前目录下的所有目录是否空,空就把目录名写入一个文件
@echo off&if not exist F:\测试\*.* set/p=该目录为空<nul&pause>nul&exit
当然这是比较简单的例子
用for做的效果会更好!
LS那位写的比较复杂,也不需要用2个for
@echo off&for /f %%i in ('dir /s/b "F:\测试\*.*"') do if not exist %%i set/p=该目录为空<nul&pause>nul&exit
当然这是比较简单的例子
用for做的效果会更好!
LS那位写的比较复杂,也不需要用2个for
@echo off&for /f %%i in ('dir /s/b "F:\测试\*.*"') do if not exist %%i set/p=该目录为空<nul&pause>nul&exit
温馨提示:答案为网友推荐,仅供参考
第1个回答 2009-12-26
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /ad /b') do (
set n=0
for /f %%j in ('dir "%%i" /a /b') do set /a n+=1
if !n!==0 echo %%i>>空目录名.txt
)
如果包括子目录,把 'dir /ad /b' 改为 'dir /ad /b /s'
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /ad /b') do (
set n=0
for /f %%j in ('dir "%%i" /a /b') do set /a n+=1
if !n!==0 echo %%i>>空目录名.txt
)
如果包括子目录,把 'dir /ad /b' 改为 'dir /ad /b /s'