1. 启动和杀死进程 :school_satchel:
- 启动程序
- start
# 打开xxx.bat
shell("start xxx.bat")
- 杀死程序
- taskkill
# 结束cmd.exe相关的所有进程(包括子进程)
shell("taskkill /f /t /im cmd.exe")
2. 查看进程 :school_satchel:
- 查看程序
- tasklist
3. 文件名查询 :school_satchel:
-
该bat程序用于查询文件夹中存在的csv文件,并且将结果生成csv格式
-
@echo off 不显示所有bash代码
-
cd /d: 修改当前目录到指定目录
-
%~dp0: 显示目标目录位置
-
dir /b: 显示目录中的文件和子目录列表:
- /b的作用是只显示文件名
-
pause: 中断执行并给出提示信息,然后由用户决定是否继续执行
-
@echo off
cd /d %~dp0
dir /b *.csv*>file.names_result.csv
参考链接:https://blog.csdn.net/weixin_40523119/article/details/102520007
4. 文件复制 :school_satchel:
-
该bat程序用于复制源文件夹内(包括子文件夹)存在的所有csv文件,到目标文件夹"new_copied_file"
-
md [string] 创建文件夹:
- string:指定文件名
-
set [variable]=[string] 创建变量:
- variable:指定环境变量名
- string:指定要指派给变量的一系列字符串
-
for /f %%i in (file) do command:
- file为文件名,按照官方的说法是,for会依次将file中的文件打开,并且在进行到下一个文件之前将每个文件读取到内存,按照每一行为一个元素,忽略空白的行
-
copy /y [source] [destination]:
- copy [source] [destination] 将一份或多份文件复制到另一个位置
- /y 不使用确认是否要覆盖现有目标文件的提示
-
@echo off
cd /d %~dp0
md "new_copied_file"
set copy_target=.\new_copied_file
for /f "delims=" %%s in ('dir /b/a-d/s "*.csv"') do (
echo %%s
copy /y "%%s" %copy_target%
)
pause
参考资料:
https://www.jianshu.com/p/80ee4ab4d33f
https://blog.csdn.net/hutuchongaini/article/details/35290989
https://www.cnblogs.com/hinata-sen/p/7443007.html