Solved Search Directory and Open File

July 19, 2012 at 08:04:13
Specs: Windows 7
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


See More: Search Directory and Open File

Report •

#1
July 19, 2012 at 10:22:27
✔ Best Answer
cls
@ECHO OFF
:begins

echo 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%.pdf

cls

echo ERROR: THAT FILE DOES NOT EXIST
goto begins

:: mike


Report •

#2
July 19, 2012 at 10:35:26
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


Report •

#3
July 19, 2012 at 10:49:58
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


Report •

Related Solutions

#4
July 19, 2012 at 12:59:55
never thought about making it look better with vbs, that's a nice touch, I was about to ask the same question.

:: mike


Report •

Ask Question