Windows bat批处理脚本统计当前文件夹内文件数量 202
2024-11-07 本文已影响0人
阿然学编程
@echo off
:: 设置代码页为GBK
chcp 936 > nul
setlocal enabledelayedexpansion
:: 指定输出文件
set "outputfile=file_names_count.txt"
:: 指定要查找的文件类型(多个用空格分隔)
set "filetypes=*.mp3"
:: 初始化计数器
set count=0
:: 删除已存在的输出文件(如果存在)
if exist "%outputfile%" del "%outputfile%"
:: 遍历当前目录下的所有指定类型的文件
for %%t in (%filetypes%) do (
for %%f in (%%t) do (
:: 获取文件名(不包括路径)
set "filename=%%~nxf"
:: 将文件名写入到输出文件
echo !filename! >> "%outputfile%"
:: 增加计数器
set /a count+=1
:: 显示进度
echo 正在处理第 !count! 个文件: !filename!
)
)
:: 将计数结果写入到输出文件
echo 总共的文件数量: %count% >> "%outputfile%"
:: 显示写入的文件数量
if %count%==0 (
echo 当前目录下没有找到指定类型 %filetypes% 的文件。
) else (
echo 已将 %count% 个文件名写入到 %outputfile%。
)
endlocal
pause
image.png