I am a CMD newbie and have a question with a batch script I am working on. I have a parent directory with 30 sub-directories containing .pdf files, and I need a filelist.txt for each sub-directory, and have each filelist.txt save as the file name of the sub-directory it belongs too. This has been completed with the script below:
@echo off
cd /d "C:\Desktop\parentDir"
for /d %%a in (*) do (
DIR /B /ON /A-D "%%a" > %%a.txt.
move %%a.txt "%%a" >nul
)
My question is how, can I remove file extensions in the output of each filelist.txt. For ex. when I run the script now, the output .txt file shows 1111.pdf 1112.pdf I need the ".pdf" removed
I know with a "for" command you can "do" echo %%~na to remove file extensions, but I have no clue how/where to factor this into the current script.
Any help is appreciated!
You are using DIR
command to list all files. It does not have a switch to hide extension.
You can replace the DIR
command with a FOR loop
, like you pointed out.
cd /d "C:\Desktop\parentDir"
for /d %%a in (*) do (
for %%f in ("%%a\*") do @echo %%~nf >> %%a.txt.
move %%a.txt "%%a" >nul
)
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.