@echo off
:: 判斷輸入路徑是不是文件夾,如果是,則獲取文件夾下的所有文件名(包括子文件夾下的)
:: 如果要文件名帶上路徑,則需要在dir這一句的%%~nxi上作改動
:: code by jm CMD@XP 2006-7-20
if exist list.txt del list.txt /q
:input
cls
set input=:
set /p input= 請輸入要進行判斷的路徑:
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
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% 文件夾下沒有單獨的文件
pause