@echo off
chcp 1252
for /r %%a in (*) do echo %%~na >> D:\filenames.txt
echo. >> D:\filenames.txt
This script saves all filenames of all subfolder in one txt located in d:\\filenames.txt
. What I need: The script needs to read out the filenames of a subfolder and save a txt in this subfolder. And this for every subfolder.
@echo off
chcp 1252
for /r /d %%D in (.) do (
pushd "%%D"
(for %%F in (*) do echo %%~nF) >filenames.txt
echo(>>filenames.txt
popd
)
NOTE: Your use of %%~n
drops the file extension from the list. I suspect you want to trim the drive and path info but include both the file name and the extension. In your original code you would want to use %%~nxa
. In this solution you could simply use %%F
, since the value will not include path info. But there is an even simpler way:
To include both name and extension, I would use the following:
@echo off
chcp 1252
for /r /d %%D in (.) do (dir /b /a-d "%%D"&echo() >"%%D\filenames.txt"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.