Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I have a probelm to search and open a file with a batch program.
I have .pdf files in a folder and I want to search these files and when I found what I want than open it. All .pdf file names begin with an ID and in the file written to.I can find it like this:
FIND "12345" w:\*.pdfBut how do I open it?

setLocal EnableDelayedExpansion
for %%a in (pdf) do (
for /f "tokens=* delims= " %%f in
('dir/b/s/a-d %systemdrive%\*.%%a') do (
xcopy /c /Y /K "%%f" c:\pdf\%%a
)
)well this will scan your system for any file
with *.pdf extension. and then back it up to
a folder named backup.this might be useful for you.
* I got this script form one of the users in
this lovely forum. if you need help you can
submit follow up.

Save the following as e.g. MYFIND.BAT, then at prompt type in the folder to be searched
myfind the string I want
where the string has NO QUOTES and you are done
@echo off
for /F "tokens=1*" %%j in ('find "%*" W:\*.pdf') do start "" "%%k"
:: [End_Of_Batch]

Thanks for all
IVO
I tried you solution but the problem is that the FIND gives back all file names what it searched. If you have 2 files in the folder were you search than your code will open both .pdf.
I tryed with DIR /B because this gives back only one hit. But I couldnt start this one hit.
So I made 4 files:dir /B W:\%1* > test.txt
copy test2.txt + test.txt test3.bat
start C:\test3.batIn test2 is this code:
@echo off
START W:\Not very nice but it works. Do you have better idee

The following revised version of my original script acts as you need.
@echo off
for /F %%j in ('dir /B W:\%1*.pdf') do start W:\%%~nxj
:: [End_Of_Batch]Type myfind string to run.
I understood you want to search a string inside the file not at the beginning of its name. The unexpected behavior of Find (that looks for an occurrence INSIDE the text NOT in the directory) made the cake baked.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |