[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 Hello123World 于 2011-7-28 13:09 编辑

这里有一个有趣的现象,批处理命令(也可能是cmd.exe本身)不能判断无扩展名的文件和文件夹的区别。
  1. @echo off
  2. Md logfile 2>nul || fsutil file CreateNew logfile 0 &Rd logfile & exit
  3. fsutil file CreateNew logfile 0 || Md logfile 2>nul & del logfile &exit
  4. pause
  5. del  logfile || rd logfile & fsutil file CreateNew logfile 0 & exit
  6. rd logfile || del logfile & md logfile & exit
复制代码
最终解决代码:
  1. @echo off
  2. Set a=
  3. pushd "%~dp0"
  4. cd logfile && Set a=1 || Set a=0
  5. popd
  6. If %a%==1 rd logfile && fsutil File CreateNew logfile 0  & exit
  7. If %a%==0 del logfile && md logfile  || fsutil File CreateNew logfile 0
  8. exit
  9. pause
复制代码

TOP

返回列表