@echo off
if exist D:\work\ goto :wjj
if exist D:\work goto :wj
goto :no_wjj_wj
:wjj
echo 是文件夹
goto :end
:wj
echo 是文件
goto :end
:no_wjj_wj
echo 既不是文件夹,也不是文件
:end作者: DOSforever 时间: 2010-12-12 13:36
Quote:
Originally posted by peterhuang at 2010-11-26 14:59:
dos的批处理太ugly了。
还是unix系统的好, -d / -f 就ok了
if [ -d $1 ];then echo "dir";elif [ -f $1 ];then echo "file";fi;
很多年前用dos的时候就对dos的命令行深恶痛绝。
刚开始的时候我也觉得 DOS 的批处理功能太弱了,但自从接触了 NDOS 即 4DOS 后就大为改观了。比如这个例子,用 4DOS 来处理也很简单
iff exist %1 then
echo %1 is a file
elseiff isdir %1 then
echo %1 is a directory
else echo %1 not exist
endiff作者: DOSforever 时间: 2010-12-12 13:39 其实在 4DOS 出现以前,我们用 DOS 自带的 COMMAND 做命令解释器也可以判断
if exist %1 echo %1 is a file
if exist %1\nul echo %1 is a directory