WindowBat实战

  • 自动拷贝文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@echo off
cls
cd ./bin

REM 打印当前文件夹中的dll名称
dir *.dll

for /r %%j in (*.dll) do (
REM 拷贝Release版的dll到指定目录
echo %%j | find "_d" || xcopy %%j E:path\Release\ /Y
REM 拷贝Debug版的dll到指定目录
echo %%j | find "_d" && xcopy %%j E:path\Debug\ /Y
)

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
@echo off
REM 首先遍历最外层的文件夹,
for /f %%i in ('"dir /ad/b/on *.*"') do (
echo "First Dir: %%~fi"
REM MKDIR OF DESTINATION
md E:\Destination\%%i
cd %%~fi
REM 获取到子文件夹之后再递归遍历子文件夹
for /f %%j in ('"dir /ad/b/on *.*"') do (
echo "Second Dir:%%~fj"
REM MKDIR OF DESTINATION
md E:\Destination\%%i\%%j
cd %%~fj
REM 拷贝每个文件到预定的路径中
for %%k in (*.las) do (
echo "Third Dir:%%~fk"
REM COPY EACH LAS FILE
xcopy %%k E:\Destination\%%i\%%j\ /E /D /R /Y
)
REM 返回到上层文件夹,继续后续的遍历
cd ..
)
REM 同理
cd ..
)
REM 脚本运行完之后不退出
pause

title:WindowBat实战

author:AmazingHao

link:http://whu-lyh.github.io/blogs/2020/03/21/WindowBat%E5%AE%9E%E6%88%98/

publish time:2020-03-21

update time:2023-09-21

| visits
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×