此 Blog 已经迁移到 http://janlay.com,并停止更新。
This blog was moved to http://janlay.com and stopped updating.

2004-5-18 9:16Zoom全屏命令提示符之 If exist 测试

在传统的 DOS 环境中,if exist 只能用来测试文件是否存在,而不能测试目录或驱动器。由于 DOS 使用“虚拟设备”机制,我们可以用 if exist c:\dos\nul 来测试是否存在 c:\dos 这个目录。这是个变通的办法。

现在没这么麻烦了。我测试了几条语句:
C:\Documents and Settings\Administrator>if exist c:\nul echo ok
ok

C:\Documents and Settings\Administrator>if exist c:\ echo ok
ok

C:\Documents and Settings\Administrator>if exist c:\abc.txt echo ok

C:\Documents and Settings\Administrator>if exist c:\windows echo ok
ok

C:\Documents and Settings\Administrator>if exist c:\windows\*.bak echo ok
ok
这个在 Windows Server 2003 命令提示符下的测试结果表明:
  • 系统仍然兼容老的虚拟设备路径;
  • if exist 可以直接测试文件、目录、驱动器是否存在
  • 作者:Author:janlay 分类:Category:Techniques 回复Comments: 引用Trackback: 阅读:Read

    回复Comments

    {commenttime}{commentauthor}

    {CommentUrl}
    {commentcontent}