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.


In your script:

for %%i in (*.pdf) do @echo %%~ni >> PDF_LIST.txt
  • Whoa that blows my mind (never really worked with command line). Ok I'll give it a shot. Thanks! Dec 17 '10 at 17:13
  • 1
    See help for to have some additional cranial stimulation. 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. Dec 17 '10 at 17:18
  • 2
    @NoCatharsis: Sorry about the typo. At the command line just use single %. Use %% in your batch file. Dec 17 '10 at 17:22
  • Cool, works like a charm - thanks a lot for the quick help. 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.

  • 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. Dec 17 '10 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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