1.获取当前目录下的所有文件名
新建一个txt文件,
文件内容
DIR *.* /B >LIST.TXT
保存,重命名为.bat文件
2.包括子目录
文件内容改为
@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 %%~nxi>>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