批處理的循環(huán)腳本
第一次運(yùn)行 執(zhí)行命令A 第二次運(yùn)行 執(zhí)行命令B 第三次運(yùn)行 執(zhí)行命令A ................ 原理很簡(jiǎn)單 用if exist 判斷 第一次運(yùn)行時(shí),不存在指定文件 ,則運(yùn)行命令A(yù),并創(chuàng)建指定文件 第二次運(yùn)行時(shí),指定文件存在 ,則運(yùn)行命令B,并刪除指定文件 第三次運(yùn)行,又不存在指定文件,............
兩個(gè)實(shí)例
1. 顯示/隱藏文件的擴(kuò)展名 (運(yùn)行并刷新后生效)
@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. 啟用/斷開(kāi)寬帶連接
@echo off if not exist c:windows\wind.txt ( break>c:windows\wind.txt rasphone /d 寬帶連接 ) else ( rasphone /h 寬帶連接 del c:windows\wind.txt ) DOS |