/* Scandir.rexx
 * Support script for pictures.fdb
 * Copyright © 1995-1996 Nils Bandener
 * $VER: scandir.rexx 3.3 (16.3.96)
 */

Options Results
Address FIASCO

Signal on Syntax
Signal on Halt
Signal on Break_C
Signal on Failure

F_LockGUI

/*
 *  Get the directory to search in
 */

F_RequestFile Drawersonly

if rc = 0 then do

    /*
     *  User did not cancel the requester
     */

    directory = result

    /*
     *  Create a list
     */

    Address Command "list >t:files" directory "lformat %s%s files pat ~(#?.info)"    /* Make a listing of all files in it */

    Address FIASCO

    F_SelectProj "pictures.fdb"     /* Only to be sure, that this is the right one */

    if RC < 10 then do

        /*
         *  Project is active now
         */

        if Open("g", "t:files", "read") then do

            do while ~eof("g")
                file = ReadLn("g")
                if file ~= "" then do
                    F_AddRecord
                    F_SetFieldCont "Picture" file
                end
            end

            call Close("g")
        end

    end
end

F_UnlockGUI

exit

/*
 *  Error handling
 */

Syntax:
Failure:
say "Error" rc "in line" sigl ":" errortext(rc)
say file pat

Halt:
Break_C:

Address FIASCO

F_UnlockGUI
F_ResetStatus

say "Break"

exit



