dos 之 for循環(小「病毒」)

需求:學習

一、自動在D盤下建立test2019文件夾;測試

二、自動在test2019下面建立100個文件,並寫入「這是文件幾的內容!」;spa

三、自動打開100個CMD運行窗口(保持打開狀態)。code

注:blog

一、此代碼僅作我的學習,和朋友開開玩笑。。。請勿惡意使用!rem

二、for循環中的循環次數,請慎重設置。循環次數過多,電腦會卡死!真的會卡死!cmd

三、若是電腦安裝的有殺毒軟件,會阻止打開文件夾!for循環

四、將下面的代碼複製到txt文本中,將文件保存爲.bat格式,便可暢玩!class

代碼以下:test

@echo off % 關閉回顯,就是在CMD窗口中不顯示這一段代碼 %
cd /d D:/  % 將當前目錄設置爲 D:/ %
if not exist test2019 md test2019  % 判斷test2019文件夾不存在是建立該文件夾%
cd /d test2019 % 將當前目錄設置爲 test2019 %
rem 使用for循環執行建立文件及打開CMD窗口
for /l %%i in (1,1,100) do (
echo 這是文件%%i的內容!> 這是for循環測試的第%%i個文件.txt
start cmd /k "mode con cols=300 lines=60 & color c0" %打開CMD窗口,並設置窗口大小,顏色%
explorer .%打開當前文件夾test2019%
)
pause

 版本二

@echo off
cd /d D:/
if not exist test2019 md test2019
cd /d test2019
for /l %%i in (1,1,1) do (
echo 嗨了%%i次!> 嗨%%i下.txt
start cmd /k "mode con cols=300 lines=60 & color 10"
start cmd /k "mode con cols=280 lines=58 & color 20"
start cmd /k "mode con cols=260 lines=56 & color 30"
start cmd /k "mode con cols=240 lines=54 & color 40"
start cmd /k "mode con cols=220 lines=52 & color 50"
start cmd /k "mode con cols=200 lines=50 & color 60"
start cmd /k "mode con cols=180 lines=48 & color 70"
start cmd /k "mode con cols=160 lines=46 & color 80"
start cmd /k "mode con cols=140 lines=44 & color 90"
start cmd /k "mode con cols=120 lines=42 & color a0"
start cmd /k "mode con cols=100 lines=40 & color b0"
start cmd /k "mode con cols=80  lines=38 & color c0"
start cmd /k "mode con cols=60  lines=36 & color d0"
start cmd /k "mode con cols=40  lines=34 & color e0"
start cmd /k "mode con cols=20  lines=32 & color f0"
)

版本二效果:

 

 

祝您玩的愉快!

相關文章
相關標籤/搜索