当前位置: 移动技术网 > IT编程>网络>Dos/Bat > 批处理的"循环"效果脚本

批处理的"循环"效果脚本

2017年12月12日  | 移动技术网IT编程  | 我要评论

第一次运行 执行命令工a
第二次运行 执行命令工b
第三次运行 执行命令工a
................
原理很简单
用if exist 判断
第一次运行时 不存在指定文件 
则运行命令a 
并创建指定文件
第二次运行时 指定文件存在 
则运行命令b
并删除指定文件
第三次运行 又不存在指定文件
............


写了两个实例 让大家可以试一下
1. 显示/隐藏文件的扩展名 (运行并刷新后生效)

@echo off
if not exist c:windows\wind.txt (
break>c:windows\wind.txt
reg add hkcu\software\microsoft\windows\currentversion\explorer\advanced /v hidefileext /t reg_dword /d 0 /f
) else (
reg add hkcu\software\microsoft\windows\currentversion\explorer\advanced /v hidefileext /t reg_dword /d 1 /f
del c:windows\wind.txt
)


2. 启用/断开宽带连接

@echo off
if not exist c:windows\wind.txt (
break>c:windows\wind.txt
rasphone /d 宽带连接
) else (
rasphone /h 宽带连接
del c:windows\wind.txt
)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网