如何制作一个清理计算机的批处理脚本

电子说

1.2w人已加入

描述

步骤1:

以这种可指示的方式,我们将编写一个脚本来清理计算机上的大多数垃圾文件,例如.temp文件,日志文件,临时帮助文件,磁盘检查文件,临时备份文件等等。除此之外,我们将为程序创建一个界面,以便用户可以控制它。 (并且看起来很棒)。

如果您希望脚本没有界面,请转到步骤3。如果要学习如何制作界面以及如何修改现有脚本,请转到下一步。 》 注意:如果您在运行脚本时遇到任何问题,请随时与我联系,或在下面发表评论。

步骤2:步骤2-如何使其工作

注意:我在脚本内添加了一些注释,所以你们知道代码。

1。单击开始。

2。在“运行”框中键入:记事本,然后按Enter。

3。打开记事本后,复制下面的代码。

4。单击“文件”,然后单击“保存”,然后导航到要保存文件的位置。对于文件名,键入“ test.bat”,如果您的Windows版本具有“另存为类型”选项,则选择“所有文件”,否则它将另存为文本文件。保存文件后,退出记事本。

注意:文件后缀名称必须为“ .bat”。

5。要运行批处理文件。 ,像其他任何程序一样双击它。批处理文件运行完毕后,将自动关闭。

步骤3:步骤3-脚本1(无界面)

在此步骤的底部,您将找到没有界面的完成程序。只需执行该程序,它将完成他的工作。 :)

@echo off

echo Cleaning system junk files, please wait…

REM displays a line of text

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% ecycled*.*

del /f /s /q %windir%*.bak

del /f /s /q %windir%prefetch*.*

rd /s /q %windir% emp & md %windir% emp

del /f /q %userprofile%cookies*.*

del /f /q %userprofile% ecent*.*

del /f /s /q “%userprofile%Local SettingsTemporary Internet Files*.*”

del /f /s /q “%userprofile%Local SettingsTemp*.*”

del /f /s /q “%userprofile% ecent*.*”

REM /f: force deleting of read-only files

REM /s: Delete specified files from all subdirectories.

REM /q: Quiet mode, do not ask if ok to delete on global wildcard

REM %systemdrive%: drive upon which the system folder was placed

REM %windir%: a regular variable and is defined in the variable store as %SystemRoot%.

REM %userprofile%: variable to find the directory structure owned by the user running the process

echo Cleaning of junk files is finished!

REM displays a line of text

echo. & pause

REM echo.: Displays a single blank line on the screen.

REM pause: This will stop execution of the batch file until someone presses “any key”

步骤4:步骤4-脚本2(带有界面)

脚本

脚本

脚本

该脚本的这一部分比上一步要难一些,但是如果您花时间阅读本文,您会发现编写脚本并不难。

下面的代码将为我们的现有程序添加一个带有徽标的简单菜单。执行脚本后,用户可以在几个选项之间进行选择。您可以根据需要自行添加,编辑或删除选项。我将说明现在的操作方法。

要添加选项,请先更新菜单。 (见图2)之后,您可以在下面添加代码行。 (请参见图3)

%errorlevel% equ 4 goto customName if

现在,您可以在下面添加代码块。 (请参见图4)

注意:最好在exit和start选项之后添加新选项。另外,请尝试保持代码整洁有序。如果以后要更改某些内容,这会更容易。

%errorlevel% equ 2 goto about if

REM custom option

:customName

/////add here what your option does///////////

pause

goto mainmenu

只需将步骤3中的代码放在我下面提到的区域即可。

@echo off

:mainmenu

cls

。..。..。..。..。..。..。..。..。..。..。..。..。..。

。..。..。..。,,:+++???????+++:,,。..。..。..。.

。..。..,~=============~~~~~::::==,。..。..。

。..。.~===============~~~~~:::::,,=。..。..

。..。.================~~~~~:::::,,=,。..。.

。..。.,:==============~~~~~:::::===。..。..

。..。.,,::::=+++======~~~++++=====,。..。..

。..。.,,:::::::~~~~~~~~~==========,。..。..

。..。..::::::::~~~~~~~~~==========。..。..。

。..。..,:::::::~~~~~~~~==========,。..。..。

。..。..,:::::::~777777777========,。..。..。

。..。..,:::::::II777~77777=======,。..。..。

。..。..。,::::::~~77~~~777~=======。..。..。.

。..。..。,:::~III~~~~~~~===77====,。..。..。.

。..。..。,::::IIII~~~~~~~77777===,。..。..。.

。..。..。.:::IIII~~~~~~~~~7777===。..。..。..

。..。..。.:::::I+~~~~~~7==77=~==,。..。..。..

。..。..。.,:::7III777~I777777===,。..。..。..

。..。..。.,::::III777~777777====,。..。..。..

。..。..。..:::::~~~~~~=7~=======。..。..。..。

。..。..。..,::::~~~~~~~~~======,。..。..。..。

。..。.,,,,,::::~~~~~~~~~======,。..。..。..。

。..。,,,,,,,,,:~~~~~~~~~==,,。..。..。..。..。

。..。..。..。..。..。..。..。..。..。..。..。..。..。

。..。..。..。..。..。..。..。..。..。..。..。..。..。

echo *********************

echo * CleanUp Menu*

echo *********************

echo * 1. Start CleanUp *

echo * 2. About CleanUp*

echo * 3. Quit *

echo *********************

choice /C:123 》nul

if %errorlevel% equ 1 goto start if %errorlevel% equ 2 goto about if %errorlevel% equ 3 goto exit

REM closes the program

:quit

exit /b

REM starts the clean up

:start

******PUT SCRIPT FROM STEP 3 HERE ******

pause

goto mainmenu

REM shows info

:about

echo *********************

echo * This batch file deletes most* echo * commen temp files stored on* echo * the windows install directory*

echo **

echo * Written by Kevin Tipker*

echo * 28/02/2016*

pause

goto mainmenu

步骤5:步骤5-完成

我希望您对编写可清理计算机的批处理文件编写脚本感到很满意。

让我休息的唯一一件事就是要求您提供一些反馈。另外,我想听听大家在下一个教学指南中应该涵盖的内容。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分