找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: wxcute

[ 新手练习题 3 ] 批处理判断目录存在与否

[复制链接]
发表于 2014-12-20 14:56:23 | 显示全部楼层
试试
  1. @echo off
  2. if not exist F:\windows\ (md F:\windows\&start F:\windows\) else

  3. (explorer F:\windows\)[color=LemonChiffon][/color]
复制代码
发表于 2015-4-23 09:35:59 | 显示全部楼层
  1. @echo off
  2. cd /d c:\windows
  3. if exist c:\windows explorer c:\windows
  4. if not exist c:\window  md c:\windows
复制代码
发表于 2015-4-23 16:11:53 | 显示全部楼层
回复 80# zzw8822


两个建议

1. 在不确定 c:\windows 是否存在的情况下就直接 cd /d 没啥意义
2. 两个 if 命令可以合并成一个 if ... else ...
  1. if exist c:\windows\ (
  2.     explorer c:\windows
  3. ) else (
  4.     md c:\windows
  5. )
复制代码
发表于 2015-5-5 12:43:36 | 显示全部楼层
方法一
  1. if exist c:\windows\ (
  2.         echo c:\windows存在
  3.         start c:\windows\ ) else (
  4.         echo c:\windows\不存在
  5.         echo 开始创建c:\windows\
  6.         md c:\windows\
  7.         start c:\windows\ )
  8. pause>nul
复制代码
方法二
  1. cd /d d:\windows&&echo 目录存在||md d:\windows
  2. explorer d:\windows
  3. pause>nul
复制代码
发表于 2015-5-8 23:33:59 | 显示全部楼层
@echo off
set str=c:\windows  
if exist %str% (start explorer.exe) else (cd /d c:\&md windows)
pause
发表于 2015-10-20 15:38:19 | 显示全部楼层
本帖最后由 wutarnow 于 2015-10-20 15:46 编辑

  1. @echo off
  2. md c:\windows 2>nul & start c:\windows\
复制代码
发表于 2016-3-31 21:51:25 | 显示全部楼层
  1. @echo off
  2. set diretory=c:\windows
  3. if exist %diretory% (explorer %diretory%) else (md %diretory%&explorer %diretory%)
复制代码
发表于 2016-4-22 15:36:44 | 显示全部楼层
@echo off
if exist D:\Windows (
   explorer D:\Windows
) else (
    md D:\Windows
)
pause
发表于 2016-11-8 21:36:31 | 显示全部楼层
@echo off
if exist c:\windows explorer c:\windows else md c:\windows
发表于 2018-7-29 13:14:14 | 显示全部楼层
  1. @echo off
  2. set specfolder=%1
  3. if not exist "%specfolder%" (
  4.         md "%specfolder%"
  5. )

  6. start "%specfolder%" "%specfolder%"
复制代码
发表于 2019-7-28 17:46:35 | 显示全部楼层
判断 C:\ 盘是否存在 WINDOWS 目录。如果存在,则用资源管理器打开目录。
不存在则创建此目录并打开。
  1. @echo off
  2. set path="C:\windows"
  3. if exist %path% explorer %path%
  4. if not exist %path% md %path%
  5. start explorer %path%
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:11 , Processed in 0.019699 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表