标题: 求助:如何判断一个目录的存在
[打印本页]
作者: baepyygy
时间: 2006-11-20 08:03
标题: 求助:如何判断一个目录的存在
怎么才能判断 "%userprofile%mydocu~1"下的目录是否存在
请教了!!
作者: andred0421
时间: 2006-11-20 15:27
if exist ?
作者: baepyygy
时间: 2006-11-20 21:34
嗯
作者: ddos0
时间: 2006-12-23 00:54
判断目录应该是 if exist X:\abc\nul dir abc exit
判断文件 if exist X:\abc echo file abc exist
搜来的
作者: lxmxn
时间: 2006-12-23 02:56
Quote: |
Originally posted by ddos0 at 2006-12-22 11:54:
判断目录应该是 if exist X:\abc\nul dir abc exit
判断文件 if exist X:\abc echo file abc exist
搜来的 |
|
第一个方法可以判断文件夹,但是第二个中的abc,if 可能会认为它是文件,也可能会认为它是文件夹,这样判断就不是很准确。
下面是一个变通的方法,如果要遍历文件夹,dir 后加上 /s 参数即可。
::判断当前目录中是否存在abc文件夹:
dir /ad/b | findstr "^abc$" >nul && echo Directory abc exist. || echo Directory abc doesn't exist.
::判断当前目录中是否存在abc.cba文件:
dir /a-d/b | findstr "^abc.cba$" >nul && echo File abc.cba exist. || echo File abc.cba doesn't exist.
作者: sa22
时间: 2006-12-23 03:11
Quote: |
Originally posted by lxmxn at 2006-12-22 01:56 PM:
下面是一个变通的方法,如果要遍历文件夹,dir 后加上 /s 参数即可。
... |
|
如果要將搜尋到的路徑代入 filedir1 ~ 5 的話應該怎麼寫呢?
作者: lxmxn
时间: 2006-12-23 03:26
Quote: |
Originally posted by sa22 at 2006-12-22 14:11:
如果要將搜尋到的路徑代入 filedir1 ~ 5 的話應該怎麼寫呢? |
|
不明白你说的是什么意思。
作者: scriptor
时间: 2006-12-24 03:16
标题: 好啊,顶
Quote: |
Originally posted by ddos0 at 2006-12-22 11:54:
判断目录应该是 if exist X:\abc\nul dir abc exit
判断文件 if exist X:\abc echo file abc exist
搜来的 |
|
好东西,以前没有注意到阿
作者: yayumyself
时间: 2006-12-24 04:13
恩,是这样的。