Computing.Net > Forums > Programming > find and open with batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

find and open with batch

Reply to Message Icon

Name: 8.passanger
Date: November 6, 2008 at 23:38:52 Pacific
OS: Windows XP
CPU/Ram: core 2 1GB
Product: asus
Comment:

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:\*.pdf

But how do I open it?



Sponsored Link
Ads by Google

Response Number 1
Name: amlife
Date: November 7, 2008 at 06:19:12 Pacific
Reply:

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.


0

Response Number 2
Name: IVO
Date: November 7, 2008 at 06:20:56 Pacific
Reply:

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]


0

Response Number 3
Name: 8.passanger
Date: November 10, 2008 at 06:55:13 Pacific
Reply:

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.bat

In test2 is this code:
@echo off
START W:\

Not very nice but it works. Do you have better idee


0

Response Number 4
Name: IVO
Date: November 11, 2008 at 03:07:11 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: find and open with batch

Open shortcut with batch file www.computing.net/answers/programming/open-shortcut-with-batch-file/16269.html

Batch Find and Extract Regex String www.computing.net/answers/programming/batch-find-and-extract-regex-string/17028.html

Make a chat program with batch www.computing.net/answers/programming/make-a-chat-program-with-batch/17794.html