Unix command; file search

dstrasin

New Member
Good morning, Progress gurus:

I have a need to install logic at the top of a program that will search for a file on a directory using 'begins' logic (since the filename changes daily by virtue of a date-stamping extension), and if that file is found, exit the program. Do any of you know how to accomplish this using a simple Unix script? I am currently employing this Progress logic (which works, but I would think this could be handled in smarter fashion):

/* FILE-SEEKER BLOCK *********************************/
def var v-file as char format 'x(60)' no-undo.
def var v-path as char format 'x(60)' no-undo.
def stream s-in.
assign
v-path = '/nfs2/Int6_*' (where Int6 is the beginning of the filename)
v-file = ''.

input stream s-in through l value(v-path) no-echo.
import stream s-in unformatted v-file.
input close.

if not r-index(substr(v-file,length(v-file) - 8),'not found') <> 0
then do:
message color message
skip(1)
'UNPROCESSED FILE NAME(S): ' v-file
skip(1)
view-as alert-box
title ' File(s) Found '.
return.
end.

else do:
message 'continue processing'
view-as alert-box.
end.
/* END FILE-SEEKER BLOCK *****************************/

Thanks in advance for your expertise.

Dave (dstrasin)
 
Hello Dave,

perhaps this is what you´re looking for. Most the same but a bit smaller...

/*----*/
def var fname as char.

input through value("ls /nfs2").
repeat:
import fname.
if fname begins "Int6_" then
/* your logic */.
end.
input close.


Clark
 
I think you can achieve that without any script using only P4GL.

Here's a sample:

Code:
DEFINE VARIABLE vfile AS CHARACTER     NO-UNDO.
/* Reading all files in the folder */
INPUT FROM OS-DIR("<folder name>").
REPEAT:
   /* Commented by KSV: Getting the next file */
   IMPORT vfile.
   /* Commented by KSV: If its name begins with something we need, show its 
   ** name and exit from loop */
   IF vfile BEGINS "<search string>" THEN
   DO:
      MESSAGE PROGRAM-NAME(1) SKIP
         vfile
         VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "DEBUG".
      LEAVE.
   END.
      
END.
INPUT CLOSE.
 
Back
Top