exists or similar command to work like grep on file system files

Bruce Easton bruce at stn.com
Wed Feb 12 06:12:45 PST 2014


On 2/11/14 11:19 PM, James Flanagan wrote:
> Server: 	FreeBSD 9.2
> Filepro:	5.7.0.4
>
> I am looking a way to have filepro verify whether a file exists using only a partial file name (like grep).  This will be used with photographs from all sorts of cameras so instead of trying to account for every possible camera filename structure, i would like to be able to supply filepro with 3-4 numbers and a directory and have filepro determine if a file with that number exists in a file name.  that will be accurate enough for what i need the code to do.
>
> below is a simple file list, and beneath that is how i would imagine i would use the exists command to accomplish what i am trying to do (however it does not appear to work with asterisk variables).  Is there either different syntax to use with the exists command, or possibly a different command that will do this?  I could use a system command that could LS the directory and then grep the result to a file, and then use exists on that output file, but i am looking to see if there is a more elegant solution self contained within filepro itself.   Thank you very much in advance.
>
> [root at filepro a]# ls
> IMGP0997.JPG	IMGP0999.JPG	IMGP1001.JPG	IMGP1003.JPG
> IMGP0998.JPG	IMGP1000.JPG	IMGP1002.JPG	IMGP1004.JPG
>
> ::aa="0998":
> :exists("/tmp/a/*"{aa{"*") eq "1":msgbox aa<"exists":
>
>
>
> James Flanagan
You could probably use the exists function but you would have to form 
each possible pattern to feed to it outside the function. Your sample 
file list does not show much variation, but based on the description of 
your needs, it sounds like you could have variation (length of 
filenames, pattern leading up to numeric portion, type of file extension).

I'm sure there are a number of ways to do this depending on your needs.  
I see R Williams has suggested the user command. That's what I was 
thinking for this as well.

Here is some code that I tested on Linux for some processing that just 
starts @menu.
(For this sample, processing runs out of "imagefinder" but does not read 
nor write to the file.)

It just asks for a pattern, then returns a vertical list in a box - up 
to 10 matches of the filenames that were found in the 
/var/www/html/images folder.  After viewing that errorbox, when the 
operator hits return, it cycles and asks for the pattern again.  I have 
it called with: ~clerk imagefinder -z findimage -y "" -s0

imagefinder/prc.findimage:

   1  -------   -   -   -   -   -   -   -   -   -   -
@menu If:
        Then: ii(2,.0)="1"; aa=""
   2  -------   -   -   -   -   -   -   -   -   -   -
If:
        Then: input popup pa(10,*) "Enter pattern: "
   3  -------   -   -   -   -   -   -   -   -   -   -
         If: @sk eq "BRKY"
        Then: exit
   4  -------   -   -   -   -   -   -   -   -   -   -
         If:
        Then: user expr = /usr/local/bin/picfind.sh
   5  -------   -   -   -   -   -   -   -   -   -   -   -
        If:     'send to picfind.sh
        Then: expr = ""{pa{""
   6  -------   -   -   -   -   -   -   -   -   -   -   -
iiloop  If: ii le "10" and expr  'read up to 10 matches
        Then: aa=aa{expr{"\n"; ii=ii+"1"; goto iiloop
   7  -------   -   -   -   -   -   -   -   -   -   -   -
         If: ii eq "2" and aa eq "\n"  'no matches
        Then: aa="None found"
   8  -------   -   -   -   -   -   -   -   -   -   -   -
         If:
        Then: errorbox aa
   9  -------   -   -   -   -   -   -   -   -   -   -
         If:
        Then: close expr; goto @menu


and for the script /usr/local/bin/picfind.sh:

# find pictures
cd /var/www/html/images
read pattern
ls -1 *"$pattern"* 2>/dev/null

Bruce




















More information about the Filepro-list mailing list