编程语言
首页 > 编程语言> > 批处理编程案例

批处理编程案例

作者:互联网

计算机信息展示

monitor.bat 内容

@echo off
rem echo. > log.txt
echo Log File >> log.txt
echo. >> log.txt
echo User : %username% >> log.txt
Date /t >> log.txt
Time /t >> log.txt
echo. >> log.txt
echo Process Ran by %username% >> log.txt
echo. >> log.txt
tasklist >> log.txt
echo. >> log.txt
echo Network Activites >> log.txt
netstat -s >> log.txt
ipconfig /all >> log.txt
exit

log.html 内容

<html>
<head><title>Log File - 筱团</title></head>
<body>
<br>
<center><h1><u> Log File </u></h1>
<i>This Log file is created by <b>筱团</b> for monitoring System Activities!</i>
</center>
<br>
<center>
<ul>
<a href="log.txt">Click here to view the Log File</a>
</ul>
</center>
</body>
</html>

效果展示

交互作用

interaction.bat 内容

@echo off

echo 1.show ip address
echo 2.show network link
echo 3.show direcotory

:main
echo Enter your option
set /p opt=

if %opt%==1 goto one
if %opt%==2 goto two
if %opt%==3 goto three
echo Invalid option
goto main

:one
ipconfig /all
pause>nul
exit

:two
network -an
pause>nul
exit

:three
dir
pause>nul
exit

效果展示

自创:密码文件夹

password.bat 内容

@echo off

md password
cd password

for /L %%a in (1,1,3) do (
md %%a
cd %%a
for /L %%b in (1,1,3) do (
md %%b
cd %%b
for /L %%c in (1,1,3) do (
md %%c
)
cd ..
)
cd ..
)

原本我想创建 0-9 的 10 层嵌套密码文件夹,一开始我的思路是回溯,然后我把 C 语言的方法都写好了,转到 bat 时发现 batch 的函数根本没有 return,也就不能执行回溯;于是我干脆改成最简单的 9 层 for 循环,但当我一开始运行,就报错 The filename or extension is too long.The system cannot find the path specified.,然后我算了一下,发现如果命令执行,总共要创建的文件夹的数量为:10^10 + 10^9 +...10^2 + 10,尼玛这就是天文数字啊,之后我删掉错误溢出的文件,显示正在删除文件,共 2207 个项目,预计耗时 5 分钟... 算了我还是改成 1-3 的 3 层嵌套密码文件夹吧,完。

效果展示

自创:日记保存

password.bat 内容

@echo off

type impromptu.md >> C:\Users\14805\Desktop\工具箱\diary.md
for /L %%a in (0,1,6) do (echo. >> C:\Users\14805\Desktop\工具箱\diary.md)
echo 选 1 打开 diary  选 2 浏览 diary
set /p opt=

if %opt%==1 goto one
if %opt%==2 goto two

:one
start C:\Users\14805\Desktop\工具箱\diary.md
exit

:two
type C:\Users\14805\Desktop\工具箱\diary.md
exit

效果展示

标签:md,log,%%,批处理,编程,echo,案例,diary,txt
来源: https://www.cnblogs.com/CourserLi/p/15355115.html