How to create scrolling window for selecting of files

rbaggetta

New Member
Hi, does anyone know how to create a directory listing to a specified path on unix, show the files, then allow the user to select the files they want. Once you know what they selected, I want the files copied to another unix directory.

So far, this little tid bit will give me a list of files in the directory.
I guess the next step would be to create a temp table of some sort, display it, and have the user select from the list. A simple "*" character next to the file would be fine. For those of you who are running MFG/Pro, this utility will help in moving files back in to the inbox for reprocessing versus having the end user call IT support and move them.


define var edi as char.
define var fn as char format "x(15)".
assign edi="ls /home/in".
input through value(edi) NO-ECHO.
repeat:
set fn.
display fn.
end.
input close.

OUTPUT:
file1.prn
file2.prn etc...​
 

jongpau

Member
Try using INPUT FROM OS-DIR("/home/in") -- you can find what OS-DIR does and how to use it in the documentation of Progress. Read the files, pop them in a temp-table and show the results in a multi-select browse; add a button and on click of that button do your processing of the files selected by the user...
 

rbaggetta

New Member
I tried that, but didn't seem to work as expected. I have this working for me now which builds a temp table. Now, how do I display the records on the screen and allow the user to select them? I am using character of progress not GUI as well.{mfdtitle.i "b+ "}

define var edi as char.

define var fn as char format "x(15)".

define var edfilename as char format "x(10)".

define var edfiledate as char format "x(10)".

define temp-table edilist

field edifile as char format "x(15)".

form

edfilename colon 9 view-as fill-in size 5 by 1

with frame a side-labels width 80.

setFrameLabels(frame a:handle).

view frame a.

assign edi="ls /ew53/in".
input through value(edi) NO-ECHO.

repeat:

set fn.

create edilist.

assign edifile = fn.

end.

input close.

for each edilist:

display edilist.

end.
 

jongpau

Member
Browses and OS-DIR work in both GUI and ChUI... Try something like this (may need some tweaking):

Code:
DEF VAR vShort AS CHAR NO-UNDO.  
DEF VAR vLong AS CHAR NO-UNDO.  
DEF VAR vAttrib AS CHAR NO-UNDO.    

DEF QUERY qFiles FOR edilist.    
DEF BROWSE bFiles QUERY qFiles 
    DISPLAY edilist.edifile       
    WITH 10 DOWN TITLE "File List":L.    

DEF FRAME fFiles               
    bFiles          
    WITH NO-LABELS NO-ATTR-SPACE.    

INPUT FROM OS-DIR("/ew53/in":U) NO-ECHO.  
REPEAT:    
  IMPORT vShort vLong vAttrib.    
  IF vShort NE ".":U AND 
     vShort NE "..":U    
  THEN DO:      
    CREATE edilist.      
    ASSIGN edilist.edifile = vShort.    
  END.  
END.  
INPUT CLOSE.    

OPEN QUERY qFiles FOR EACH edilist.  
ENABLE bFiles WITH FRAME fFiles.
 

rbaggetta

New Member
Thanks for your feedback. I ended up doing it this way. This seems to work as it should. Program reads a directory, then displays its files. User press up/down arrow keys to move through records in a scroll windows. Press GO key and file is copied to new location.

One problem I had is that when the list box display, the first record is not selected automatically. If user presses PF1(GO), it would error out to /usr/bin/ksh :?.
So, to fix it, I add an IF statement to check if choice was "?", in this case, ? represented the same unknow character that progress was using.

Do you know how to select the first record in the list automatically?
Code:
[font=r_ansi][size=2]define stream dirlist.
 
define variable f-name as character format "x(30)" no-undo.
 
define variable choice as character format "x(30)" initial "" no-undo.
 
define variable choice2 as character format "x(30)" no-undo.
 
define variable list_contents as character format "x(800)" no-undo.
 
define variable dir as character format "x(20)" 
 
initial "/ew53/qadedi/arch/" no-undo.
 
define variable dirin as character format "x(10)"
 
initial "/ew53/in/" no-undo.
 
define variable sl as character VIEW-AS SELECTION-LIST 
 
SCROLLBAR-VERTICAL
 
INNER-CHARS 30
 
INNER-LINES 13
 
SORT.
 
define frame b sl.
 
INPUT STREAM dirlist FROM OS-DIR(dir).
 
IMPORT STREAM dirlist f-name.
 
list_contents = f-name.
 
REPEAT:
 
IMPORT STREAM dirlist f-name.
 
list_contents = list_contents + "," + f-name.
 
END.
 
INPUT CLOSE.
 
list_contents = LEFT-TRIM(list_contents,".,..,").
 
DISPLAY "Use up/down arrow keys to highlight file, press <ENTER> key" with 
 
frame sl.
 
DISPLAY "then press PF1 to copy file to inbox." with frame sl.
 
 
 
sl:LIST-ITEMS = list_contents.
 
repeat:
 
UPDATE sl WITH FRAME b NO-LABELS NO-BOX.
 
choice = sl:SCREEN-VALUE.
 
choice2 = "cp " + dir + choice + " " + dirin.
 
 
 
if choice <> ? then do: 
 
OS-COMMAND silent value(choice2).
 
display skip (1)
 
"Selected file has been copied back into inbox for reprocessing"
 
with frame b.
 
pause.
 
end.
 
else do: 
 
display "Press <ENTER> key to select file before pressing PF1".
 
end. 
 
end.
[/size][/font]
 

rbaggetta

New Member
I tried that, didn't work. Something needs to take place after the UPDATE code runs, which displays the files in the list box. If you figure it out, let me know.
 

jongpau

Member
Oh, you use UPDATE!! Duh, silly me (I don't use that statement anymore)...

Have you tried (before the repeat loop with the update) to do:
sl = entry(1,sl:list-items)
 

rbaggetta

New Member
Yes, this seems to work, it puts the select on the 2nd line. If I try value zero on the entry, I get an error:

value 0 is out of range of entry list
file1.prn,file2.prn,file3.prn etc...

if I put value 2, it show the last scroll from the bottom of the window.
so I guess this will have to do...thanks

Code:
[font=r_ansi][size=2]  sl:LIST-ITEMS = list_contents.
  sl = entry(1,sl:list-items).
  repeat:
[/size][/font]
 

jongpau

Member
That is due to the fact that you have your selection list sorted. This means that the entries in the list-items attribute don't have to be the same as the order in which the selection list displays them... take away the sort and you should see that the first line will be selected (well, that is the expected behaviour of course).
 

ddegroot

Member
Hi rbaggetta,

Hi About reusing some of the stuff already in Progress, called : adecomm/_filecom.p

It displays the standard Windows Open / Save File Dialog Box. Here is how to call it.

Regards,

DIederik


/*
* Send a file to my current workstation
*
*/

DEFINE var p_Filter AS char NO-UNDO.
DEFINE var p_Dir AS char NO-UNDO.
DEFINE var p_Drive AS char NO-UNDO.
DEFINE var p_Save_As AS log NO-UNDO. /* YES = save as*/
DEFINE var p_Title AS char NO-UNDO.
DEFINE var p_Options AS char NO-UNDO.
DEFINE var p_File AS char NO-UNDO.
DEFINE var p_Return_Status AS log NO-UNDO.

DEFINE VARIABLE reportName AS character FORMAT "x(50)".
DEFINE VARIABLE commandLine AS character FORMAT "x(50)".

{mfdtitle.i "Send Report"}

FORMAT
reportName COLON 15
"Leave empty to browse" AT 17
WITH FRAME a SIDE-LABELS WIDTH 80 ATTR-SPACE.

FORMAT
"" COLON 1
WITH FRAME b NO-LABELS WIDTH 80.

ASSIGN p_Dir = "/ext0/mfgwork".
ASSIGN p_Filter = "*.prn".
ASSIGN p_Title = "Select file to Download".
ASSIGN p_File = "*.prn".
.

REPEAT:

UPDATE
reportName LABEL "Report Name"
WITH FRAME a.

{mfquoter.i reportName}

IF (reportName = "") THEN
DO:
DISPLAY "Starting browse" SKIP WITH FRAME b.
RUN adecomm/_filecom.p (
INPUT p_Filter,
INPUT p_Dir,
INPUT p_Drive,
INPUT p_Save_As, /* YES = save */
INPUT p_Title,
INPUT p_Options,
INPUT-OUTPUT p_File,
OUTPUT p_Return_Status).

/* Set filename */
reportName = p_File.
END.
ELSE
IF (SEARCH(reportName) <> ?) THEN
DO:
commandLine="lsz " + reportName.
PUT UNFORMATTED "Sending : " reportName SKIP.
UNIX VALUE(commandLine) SILENT.
PUT UNFORMATTED "Sent." SKIP.
END.
ELSE
DISPLAY "File not found" SKIP WITH FRAME b.
END.
 

Afshin

New Member
Hi and thanx alot to give oss this usefull code.

I mess {mfdtitle.i "Send Report"} and {mfquoter.i reportName}
Could you please give location of those include file.

best regards.
 
Top