Batch processing (BAT) gets the list of all files in the specified directory

Time:2020-10-26

Judge whether the input path is a folder or not. If so, get all the file names under the folder (including those under the subfolders)
If you want to add a path to the file name, you need to change it in% ~ nxi of the “dir” sentence

@echo off
:: judge whether the input path is a folder. If so, get all the file names under the folder (including those under the subfolders)
:: if you want the file name to carry a path, you need to change it in% ~ nxi of "dir"
::       code by jm [email protected] 2006-7-20
if exist list.txt del list.txt /q
:input
cls
set input=:
Set / P input = please enter the path to judge:
set "input=%input:"=%"
: the above sentence is to judge whether there are quotation marks in% input%, and reject them if any.
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
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_ There are no separate files in the dir% folder
pause

After the development of small editor test, normal operation.