Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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.

share|improve this question
up vote 14 down vote accepted

In your script:

for %%i in (*.pdf) do @echo %%~ni >> PDF_LIST.txt
share|improve this answer
Whoa that blows my mind (never really worked with command line). Ok I'll give it a shot. Thanks! – NoCatharsis Dec 17 '10 at 17:13
See help for to have some additional cranial stimulation. – Dennis Williamson Dec 17 '10 at 17:17
I corrected (what I think was) your typo in the code and ran this command: for %%i in (*.pdf) do @echo %%~ni >> PDF_LIST.txt I'm getting the response "%%i was unexpected at this time" and no other output. – NoCatharsis Dec 17 '10 at 17:18
@NoCatharsis: Sorry about the typo. At the command line just use single %. Use %% in your batch file. – Dennis Williamson Dec 17 '10 at 17:22
Cool, works like a charm - thanks a lot for the quick help. – NoCatharsis Dec 17 '10 at 17:26

Most text editors (including notepad) have find and replace. Just use it to find all ".pdf" and replace it with "". Done :)

You can set this as macro in word, as well.

share|improve this answer
Yes, I use Notepad++ to do this right now - however I was just wondering if there was a way to cut out one more step by writing it into a script. – NoCatharsis Dec 17 '10 at 17:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.