12

I have this batch:

for /f %%a IN ('dir /b *.pdf') do call convert.exe %%a

This gets every pdf file thats in the same folder as convert.exe. I want to be able to say where the PDF resides. What do I have to change?

Thanks!

EOB
  • 2,975
  • 17
  • 43
  • 70

1 Answers1

24

If the directory name can be hardcoded, then it will be

for /f %%a IN ('dir /b /s "Disk:\Your\Directory\Name\*.pdf"') do call convert.exe %%a

Note that this will also return all .pdf files in subdirectories of Disk:\Your\Directory\Name.

Sergey Kudriavtsev
  • 10,328
  • 4
  • 43
  • 68
  • I think /b is wrong, I need the full path ... right now, I only get the filename, not the full path. And thus the param for convert.exe is only a file, without path. – EOB Jan 12 '12 at 14:12
  • @EOB: If you need to get full paths then you need to add /s, but leave /b. Modified my answer accordingly. /b suppresses `dir` headers in output - you definitely don't want them for batch processing. – Sergey Kudriavtsev Jan 12 '12 at 14:17
  • 1
    Notice: For in () do requires '(' and ')' in Windows 7 command line – Jackie Feb 12 '14 at 01:54