# 批处理BAT(win下的dos命令)

  1. win11打开IE

    新建文本文档,代码复制进去,CreateObject("InternetExplorer.Application").Visible=true 后缀名改为vbs即可

  2. 查看电脑配置cmd输入 dxdiag

  3. 任务管理器 taskmgr

  4. 端口被占用 Port 8080 was already in use

    netstat -ano | findstr "8080" 任务管理器(Ctrl+Alt+Del)结束任务或者 taskkill -pid 进程号 -f

# 常用命令

# ping ip

  1. 批量ping 192.168.1.1-255网段内的所有IP地址,(1,1,255)起始值1,结束值255,递增1
for /L %d in (1,1,255) do ping 192.168.1.%d
1
  1. ping结果自动保存到txt
for /L %d in(1,1,255) do ping 192.168.1.%d >> along.txt
1
  1. 把ping结果提取出IP,保留IP地址
for /l %D in (1,1,255) do (ping 192.168.1.%D -n 1 && echo 192.168.1.%D>>通.txt || echo 192.168.1.%D >>不通.txt)
1
  1. 要ping不同网段,读取ip.txt文件里的ip
for /f %d in (ip.txt) do (ping %d -n 1 && echo %d >>通.txt || echo %d >>不通.txt)
1
  • ip的正则
((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))
1

# 代码片段

  1. 一次性创建n个txt文件在C:\Users\biubiu\Desktop\test\下
#创建4个txt
@for /l %%a in (1 1 4) do @cd.>C:\Users\biubiu\Desktop\test\%%a.txt
1
2
  1. 创建n个txt重命名
# 1.txt
# 2.txt
# 3.txt
# 4.txt
# ....
# 12.txt
# [--------重命名后--------]
# list01.txt
# list02.txt
# list03.txt
# list04.txt
# ....
# list12.txt


@echo off&setlocal EnableDelayedExpansion

set a=1
for /f "delims=" %%i in ('dir /b *.txt') do (
    if not "%%~ni"=="%~n0" (
        if !a! LSS 10 (ren "%%i" "list0!a!.txt") else ren "%%i" "list!a!.txt"
        set/a a+=1
    )
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  1. 打包vuepress,并且上次到GitEE
@echo off

::获取管理员权限
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit

cd /d "%~dp0"





:: 睡眠2秒
timeout /T 2 >nul



::进入对应目录 准备提交代码
cd C:\Users\biubiu\Desktop\biubiu-note\note-code
::git status


echo "=====================================》"
echo "=====================================》"
echo "=========Git Start Commit============》"
echo "=====================================》"
echo "=====================================》"


set /p msg=请输入提交注释:

git add .

git commit -m %msg%

git pull

git push


echo 提交完成,提交信息为 %msg%


:: 睡眠2秒
timeout /T 2 >nul




echo "=====================================》"
echo "=====================================》"
echo "=========NPM RUN Vurepress===========》"
echo "=====================================》"
echo "=====================================》"


::编译代码
call npm run docs:build


echo "=====================================》"
echo "=====================================》"
echo "==========Copy Files Start===========》"
echo "=====================================》"
echo "=====================================》"


::复制编译后得代码到指定文件夹
echo "-------------copy start---------------"

xcopy C:\Users\biubiu\Desktop\biubiu-note\note-code\docs\.vuepress\dist\*.* C:\Users\biubiu\Desktop\biubiu-note\note /s

echo "-------------copy end---------------"




:: 睡眠2秒
timeout /T 2 >nul





::git提交
echo "-------------Git Begin-------------"

cd C:\Users\biubiu\Desktop\biubiu-note\note

::git status
::set /p msg=输入gitpage提交信息:

git add .
git commit -m %msg%
git pull
git push

echo git-page提交完成

echo "-------------Git End-------------"

pause
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  1. 批量创建目录,并且把xxx文件复制到每个目录中
@echo off
@REM 批量创建的目录把createQuxian.cmd文件复制到个子目录中
@REM 博客地址 blog.weiyigeek.top
mkdir delete other photo_bak photo_ksh photo_ksh.rar photo_ksh_backup  photo_ksh_log photo_rar photo_rar_log photo_sfzh_f photo_sfzh_z temp demo

for /f "delims=" %%N in ('dir /A:D /B') ^
do ( 
  xcopy "西部影视大数据综合服务平台优化(1).docx" %%N /y
)
pause
1
2
3
4
5
6
7
8
9
10
  1. 使用批处理dump备份MySQL指定库
@echo off
@REM 数据库备份案例
title mysqldump example
color 8a

@REM 接收位置参数变量
set user=%1
set pass=%2
set database=%3

@REM 验证位置参数
if "%user%"=="" goto usage  
if "%pass%"=="" goto usage
if "%database%"=="" goto usage

set BackupFile=%database%-%date%-%time:~0,2%%time:~3,2%%time:~6,2%%time:~8,2%.sql

@REM 备份到用户目录中
@REM C:\Users\WeiyiGeek\weiyigeek-2023-08-02-172836.8.sql
mysqldump.exe -u %1 -p%2 %3 > %userprofile%\%BackupFile%
echo Successful Export MySQL DatabaseSQL File. 
goto end

:usage
echo Usage:%0 -u User -pPass DatabaseName

:end
pause
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28