batch file Find pdf's based on user input

July 3, 2016 at 17:03:36
Specs: Windows 7
I'd like to know if it's possible to have a batch file ask for user input and use the user input to search for .pdf files in various locations based on the user input and then output the results to windows explorer. I've hashed a batch file together but it's really out of my league. Any help appreciated.

@ECHO OFF
SET 1=Model A
SET 2=Model B
SET 3=Model C

SET 100=Variant 100
SET 200=Variant 200
SET 300=Variant 300

SET 01=Version 01
SET 02=Version 02
SET 03=Version 03

SET /P Model=Please enter Model number i.e 1, 2, 3:
SET /P Variant=Please enter Variant i.e 100, 200, 300:
SET /P Version=Please enter Version i.e 01, 02, 03, etc:
FIND /C:"%Model%""%Variant%""%Version%" [C:\"%Model%"\"%Variant%"\"%Version%" *.pdf | explorer /select,"%WINDIR%
pause
end

Thanks,
Paul.


See More: batch file Find pdfs based on user input

Report •

#1
July 3, 2016 at 22:05:43
This I am not understanding:
FIND /C:"%Model%""%Variant%""%Version%" [C:\"%Model%"\"%Variant%"\"%Version%" *.pdf | explorer /select,"%WINDIR%

Do you mean something like:
dir /b /s c:\%model%\%variant%\%version%\*.pdf
?. I'll just wait for forum developments, since I'm clueless...


Report •

#2
July 4, 2016 at 03:21:19
Basically I want a batch file where the user is asked which Model, Variant and Version they require as there are other folders which contain pdf's also. I then wanted to run the find command with the user inputted keywords in and output the results to Windows Explorer. The variables that come from the user input would dictate which directory the search would take place.

So, if the user enters "Model A, Variant 200, Version 01" then the Find command would search the pdf files in the directory C:\Model A\Variant 200\Version 01 and display the results of the search in Windows Explorer. I hope this makes more sense.

I will try your suggestion though and let you know. Maybe I was trying to over complicate it.
Thanks.

message edited by par4724


Report •

#3
July 4, 2016 at 06:42:03
The FIND command looks in text files, not at file names. Are you sure that's the command you want?

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
July 4, 2016 at 08:58:38
I tried the above suggestion with the dir command but it didn't work. Here's what I have so far: -

@ECHO OFF
SET 1=Model A
SET 2=Model B
SET 3=Model C

SET 100=Variant 100
SET 200=Variant 200
SET 300=Variant 300

SET 01=Version 01
SET 02=Version 02
SET 03=Version 03

SET /P Model=Please enter Model number i.e 1, 2, 3:
SET /P Variant=Please enter Variant i.e 100, 200, 300:
SET /P Version=Please enter Version i.e 01, 02, 03:
dir /b /s C:\%model%\%variant%\%version%\*.pdf | explorer /select,"%WINDIR%
pause
end
The path that I am trying to get to is C:\Model A\Variant 100\Version 01. Within this path are the pdf's that I am trying to pipe to Windows Explorer. I have also tried putting parenthesis around the variable as they do contain spaces but it displayed "the system cannot find the path specified. Press any key to continue...

Thanks.

message edited by par4724


Report •

#5
July 4, 2016 at 21:48:10
Ah. I think I got it for part "A", to convert user input to strings which are subdirs to be searched for pdf files. The thing I don't know is how to pipe this collection to windows explorer. But here's as far as I got:
@echo off & setlocal enabledelayedexpansion
SET 1=Model A
SET 2=Model B
SET 3=Model C

SET 100=Variant 100
SET 200=Variant 200
SET 300=Variant 300

SET 01=Version 01
SET 02=Version 02
SET 03=Version 03

SET /P Model=Please enter Model number i.e 1, 2, 3:
SET /P Variant=Please enter Variant i.e 100, 200, 300:
SET /P Version=Please enter Version i.e 01, 02, 03, etc:

echo looking for pdf's in "c:\!%model%!\!%variant%!\!%version%!"
pause
dir /b /s "c:\!%model%!\!%variant%!\!%version%!\*.pdf"
::=== end snip
I believe this will get the list of files and their fullpaths. You're way ahead of me when it comes to presenting this list to explorer as in "explorer /select" - but maybe I'm overcomplicating things by assuming more than one file qualifies. If only one file is expected, and you want to open it, you only need to open it from the filename. I had no luck with "explorer /select". To open the file, one method using start::
for /f "tokens=*" %%a in ('dir /b /s "c:\!%model%!\!%variant%!\!%version%!\*.pdf"') do start %%a
which should open the file in it's default application (pdf usually adobe acro but that's locally determined).


Report •

#6
July 5, 2016 at 08:01:21
Thanks for your answer nbrane, i'm definitely not way ahead of you. The windows explorer snip was the result of hours of scouring forums for answers and I found this below to display the latest file: -
for /f %%f in ( 'dir /a-d /o-d /b "%WINDIR%"' ) do (
explorer /select,"%WINDIR%\%%f"
goto 1
)
:1
Any ideas how I could use this? I have tried but have not managed to get it to work yet.
Thanks again.

Report •

#7
July 5, 2016 at 11:35:33
Why are you stuck on %WINDIR%? Are you shoving PDF files in C:\Windows? Because that is a bad idea.

The more this thread goes on, the more confused I get. Maybe it's time to sit down and explain what you're attempting (including full paths), instead of showing what you're doing.

SET /P Model=Please enter Model number i.e 1, 2, 3:
SET /P Variant=Please enter Variant i.e 100, 200, 300:
SET /P Version=Please enter Version i.e 01, 02, 03, etc:
FOR %%a IN ("C:\%Model%\%Variant%\%Version%\*.pdf") DO explorer /select,"%%~Fa"
PAUSE

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#8
July 5, 2016 at 19:52:19
I concur with Razor at this point. If you get the correct path echoed from my snip, then, looking at your previous submissions, I gather you want to take the latest pdf only? In that case, the part:
for /f %%f in ( 'dir /a-d /o-d /b
is correct to that point, but %windir% probably has nothing at all to do with anything, especially anything you want to mess around with. That said, maybe this is what you want, starting from the last "echo" in my previous snip:

echo looking for pdf's in "c:\!%model%!\!%variant%!\!%version%!"
pause
for /f "tokens=*" %%a in ('dir /b /s /o-d "c:\!%model%!\!%variant%!\!%version%!\*.pdf" do (
set xx=%%a
goto :next
)
goto :eof
:next
echo opening file %xx%
start %xx%
goto :eof
::=== end snip
that opens the file itself. If you want to open the whole directory, then you just want to:
start "c:\!%model%!\!%variant%!\!%version%!"

which will open the directory in GUI\explorer for the user to work with. I had no luck
with using "explorer /select" to open a file, only directory. And I suspect that %windir% only crept in because you "transposed" code from some other application not relevant to this objective. Kind of like those bits of DNA that hang around because no agency saw fit to remove or modify them.


Report •

#9
July 5, 2016 at 21:03:31
Just FYI, but the difference between START and EXPLORER /SELECT is the former opens a window do the directory in question, while the latter highlights an entry in that directory as well.

How To Ask Questions The Smart Way


Report •

Ask Question