【橘猫库】bat扫描目录及其子目录下的所有文件名

bat,批处理文件,在DOSWindows(任意)系统中,.bat文件是可执行文件,由一系列命令构成,其中可以包含对其他程序的调用。这个文件的每一行都是一条DOS命令(大部分时候就好像我们在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(notepad)等任何文本文件编辑工具创建和修改批处理文件。

该段bat代码,用于扫描目录及其子目录下的所有文件名称,并存储至list.txt中

使用方法:

新建一个文本文档,将代码复制进去,后缀名由.txt修改为.bat,保存后运行
cmd窗口输入绝对路径名,如E:\迅雷下载,再回车,即可扫描出所有文件,存储至list.txt中,可复制到excel再处理。

代码

@echo off

if exist list.txt del list.txt /q
:input
cls
set input=:
set /p input=Please input path:
set "input=%input:"=%"
:: 上面这句为判断%input%中是否存在引号,有则剔除。
if "%input%"==":" goto input
if not exist "%input%" goto input
for %%i in ("%input%") do if /i "%%~di"==%%i goto input
pushd %cd%
cd /d "%input%">nul 2>nul || exit
set cur_dir=%cd%
popd
:: %%~nxi只显示文件名,%%i显示带路径的文件信息
for /f "delims=" %%i in ('dir /b /a-d /s "%input%"') do echo %%i>>list.txt
if not exist list.txt goto no_file
start list.txt
exit

:no_file
cls
echo %cur_dir% Folder does not have a separate document
pause
发布了6 篇原创文章 · 获赞 16 · 访问量 3300

猜你喜欢

转载自blog.csdn.net/qq_35341203/article/details/94588456