Ok, so I have a client who would like me to come up with some sort of script or batch file that will search a particular directory for a PDF and then open the specified PDF. The main directory contains multiple folders with PO numbers as their folder names. Then inside that folder is the actual PDF with the same PO number as the title. I need to be able to search the main directory for the PO number then open the containing PDF in as few steps as possible. I am not too experience with scripting or batch files, so the more elaborate the explanation the better. Thanks,
Anthony
cls
@ECHO OFF
:beginsecho ENTER x to leave
echo ++++++++++++++++++++++++++++++++++
echo PLEASE ENTER YOUR EXACT PO NUMBER
echo ++++++++++++++++++++++++++++++++++set /p ponum="enter po number: "
if %ponum% equ x goto:eof
If exist c:\%ponum%\%ponum%.pdf start c:\%ponum%\%ponum%.pdfcls
echo ERROR: THAT FILE DOES NOT EXIST
goto begins:: mike
Thanks Mike, I tried the code and it worked great. However I did not realize that some of the folders contain other letters as well. Is there some way to say "if it contains these characters, then open the folder and the file"?
-Anthony
Change the path of the root directory to your "main" directory, excluding a trailing \. @echo off set root=c:\test pushd %root% >%temp%\_.vbs echo wscript.echo inputbox("Enter PO Number:","Enter PO Number") for /f "delims=/" %%i in ( 'cscript //nologo %temp%\_.vbs' ) do ( for /f "tokens=*" %%d in ( 'dir /b /s /a-d %%i.pdf' ) do ( %%d & >nul del _.vbs ))Edit: Can you explain a little better, or maybe show what you are referring to by other letters? Do you mean the PDF filename doesn't always match the directory name?
Tony
never thought about making it look better with vbs, that's a nice touch, I was about to ask the same question. :: mike
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |