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

2019-09-19 07:00:50丽君

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


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

@echo off
if not exist c:windowswind.txt (
break>c:windowswind.txt
reg add hkcusoftwaremicrosoftwindowscurrentversionexploreradvanced /v hidefileext /t reg_dword /d 0 /f
) else (
reg add hkcusoftwaremicrosoftwindowscurrentversionexploreradvanced /v hidefileext /t reg_dword /d 1 /f
del c:windowswind.txt
)


2. 启用/断开宽带连接

@echo off
if not exist c:windowswind.txt (
break>c:windowswind.txt
rasphone /d 宽带连接
) else (
rasphone /h 宽带连接
del c:windowswind.txt
)
相关文章 大家在看