Solved How would I use a bat file to open the most recent pdf

November 11, 2015 at 17:05:21
Specs: Windows 7
I have a way to monitor a directory for a new file, in this case a scanned pdf, now I just need a bat file to open that newest pdf file when it's created. I've seen examples of ways to find the newest file but not open it. Thank you in advance for your time, I'm grateful.

I believe I use:
start AcroRd32.exe /A 1.pdf
AcroRD32.exe /A 1.pdf

To launch Adobe to read the file, but I need it to specifically open the just scanned newest *.pdf

Again, thank you in advance.

message edited by Elec99

See More: How would I use a bat file to open the most recent pdf

Report •

November 12, 2015 at 02:36:25
✔ Best Answer
DIR can list files in a folder by creation date, you can also specify only .pdf files.
You can parse the output of the DIR command, and break the loop after the first line:

@Echo off
:: Not tested
for /f "tokens=*" %%A in ('dir /b /a:-d /o:-d "*.pdf" 2^>nul') do (
        AcroRD32.exe /A %%A
        goto :break
pause > nul

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ

Report •
Related Solutions

Ask Question