Windows – How to hide file extensions in a command prompt /dir output

command linewindows

What I want to do seems very simple:
I have a folder in Windows containing items of various types including PDF files, TXT files, and subdirectories. I am writing a one line .bat file to pull ONLY the PDF file names into a new text file.

So far this is what I have in the .bat:

dir *.pdf /b > PDF_LIST.txt

This gives the following output in a PDF_LIST.txt file:

A.pdf
B.pdf
C.pdf

I would like to drop the ".pdf" portion of each line in the txt file, since I obviously know already that each file is in PDF format by the *.pdf parameter in my dir statement.

This would just make it easier for me to copy/paste all the file names directly from the text file into a word document for a transmittal I'm sending to my customer. If you can suggest a better or easier way to get the file list without using a batch file that would also would be helpful.

Best Answer

In your script:

for %%i in (*.pdf) do @echo %%~ni >> PDF_LIST.txt
Related Question