BAT教程【新手教程第二期】

置顶 精华 发表在    小小编程家 11-02 21:45:02

1 2171 1

4.C盘空间不够?
===========================
下面的是从网上摘抄的,有改动
===========================
@echo off 
title [清理垃圾]
color 2f
mode con: cols=20 lines=2
del /f /s /q %systemdrive%*.tmp&del /f /s /q %systemdrive%*._mp 
del /f /s /q %systemdrive%*.log&del /f /s /q %systemdrive%*.gid 
del /f /s /q %systemdrive%*.chk&del /f /s /q %systemdrive%*.old 
del /f /s /q %systemdrive%recycled*.*&del /f /s /q %windir%*.bak 
del /f /s /q %windir%prefetch*.*&rd /s /q %windir%temp & md %windir%temp 
del /f /q %userprofile%cookies*.*&del /f /q %userprofile%recent*.* 
del /f /s /q "%userprofile%Local SettingsTemporary Internet Files*.*" 
del /f /s /q "%userprofile%Local SettingsTemp*.*"
del /f /s /q "%userprofile%recent*.*" 
============================
这个批处理可以清理系统里面的垃圾
下面讲一下各个新词的意思
============================
"title"使用格式跟echo差不多
在最上面的显示框内显示输入的文字
==========
"mode con: cols=20 lines=2"
改变批处理界面的大小 数字可以改变
==========
"del"删除命令,可以删除文件,不可以删除文件夹
"/f /s /q" 是参数,以后讲
==========
"%systemdrive%*.tmp&del /f /s /q %systemdrive%*._mp"
是删除文件的位置和名字 "*.*" 代表所有名字的所有后缀名
假设: del C:Documents and SettingsAdministrator桌面123.txt
就是删除在桌面的名字叫"123"的文本文档
==========
"&"在一行内执行多个命令
其他意思以后再讲
打法:Shift + 7=&
==========
你学会了吗?


5:神奇的if
==========
@echo off
:s
echo 门锁系统(密码:12345)
set /p des=
if "%des%"=="12345" goto a
echo 输入错误
cls
goto s
:a
echo 密码正确
pause
==========
大家可以看到,本篇文章已经步入"看不懂"时期了
只要你前面没学好,后面也没指望看懂了
==========
:s~的意思是:记录点"s"
去到记录点s的命令很多读者想必已经找到了
那就是"goto s"
"goto s"去记录点"s"并执行下面的命令
提示:用goto命令时如果没有那个记录点的话则自动退出
==========
if "%des%"=="12345" goto s
这条命令什么意思了?需要联系上一条命令
set /p des=~输入内容,把内容输入到"des"的意思中
if "%des%"=="12345" goto a
就是如果"des"的意思是"12345"则执行"goto a"的命令
%des%和12345前面和后面都要打上英文的双引号
看不懂的多读几遍,就看懂了
以后还可以学有关"lss"等命令
==========
我说了那么多,其实就是讲if的用法


6:实战使用
======================
本篇文章版权归作者所有
======================
@echo off&color 2f&mode con: cols=35 lines=5
cls
:xt
echo.
echo =批处理小系统=
echo.
echo [1:关机 2:写入文档]
echo [3:清理垃圾]
set /p sz=
if "%sz%"=="1" goto gj
if "%sz%"=="2" goto xie
if "%sz%"=="3" goto ql
cls
echo 输入错误
ping /n 2 127.0.0.1 >nul
goto xt
:gj
echo 确认? [y/n]
set /p qrd=
if "%qrd%"=="y" goto gj
if "%qrd%"=="n" goto xt
cls
echo 输入错误
ping /n 2 127.0.0.1 >nul
goto xt
:gj
shutdown -s -f -t 0
goto die
:xie
cls
echo 不想打了输ok回去
echo.
set /p d=
if "%d%"=="ok" goto xt
echo ----------------------- >>bat打字.txt
echo %d%>>bat打字.txt
:f
echo.
set /p h=
if "%h%"=="ok" goto xt
echo %h%>>bat打字.txt
goto f
:ql
cls
echo 准备清理系统垃圾....
ping /n 3 127.0.0.1 >nul
del /f /s /q %systemdrive%*.tmp&del /f /s /q %systemdrive%*._mp 
del /f /s /q %systemdrive%*.log&del /f /s /q %systemdrive%*.gid 
del /f /s /q %systemdrive%*.chk&del /f /s /q %systemdrive%*.old 
del /f /s /q %systemdrive%recycled*.*&del /f /s /q %windir%*.bak 
del /f /s /q %windir%prefetch*.*&rd /s /q %windir%temp & md %windir%temp 
del /f /q %userprofile%cookies*.*&del /f /q %userprofile%recent*.* 
del /f /s /q "%userprofile%Local SettingsTemporary Internet Files*.*" 
del /f /s /q "%userprofile%Local SettingsTemp*.*"
del /f /s /q "%userprofile%recent*.*" 
cls
echo 清理完成!
ping /n 2 127.0.0.1 >nul
goto xt
===============
是不是第一此看到就放弃了?
其实逐句的看,其实很轻松
===============


7:幸运机(random随机数)
============
哈哈哈,经过了6讲批处理的课,是不是感觉自己是批处理高手了了?
---现实是残酷的
============
提示:作者给自己起了个名,叫"鸡蛋"
============
@echo off&title 抽奖机V1.0&mode con: cols=30 lines=6&color 2f
set /a c=%random%%%6
if "%c%"=="0" goto 0&cls
if "%c%"=="1" goto 1&cls
if "%c%"=="2" goto 2&cls
if "%c%"=="3" goto 3&cls
if "%c%"=="4" goto 4&cls
if "%c%"=="5" goto 5&cls
:0
echo 运气值:0
echo.
echo ......不多说
echo (惨)太(不)好(忍)了(睹)
pause>nul
goto end
:1
echo 运气值:20
echo.
echo (狗死运)
echo 不要出去哦......
pause>nul
goto end
:2
echo 运气值:40
echo.
echo 比(假)较(的)差 
echo 小心为妙 
pause>nul
goto end
:3
echo 运气值:60
echo.
echo 一般般吧...
echo 还可以,不算差
pause>nul
goto end
:4
echo 运气值:80
echo.
echo 矮油不错哦
echo 不要高兴哦
pause>nul
goto end
:5
echo 运气值:万汗脚
echo.
echo 哇哇哇哇哇哇
echo 快去买彩票
pause>nul
goto end
==================
越到后面越简单哦
==================
set /a c=%randow%%%6~就是在1到5中随机挑一个数到"c"的意思里.
==================
%randow%%%6~后面跟的数就是: (你想要最大的数)+1
==================
简单吗? 简单吗?


登录或注册后发布评论