Daniel
Daniel

Reputation: 11

EXISTS function in an SQR

In an SQR where if we want to check if a file exists on the server on an Oracle PeopleSoft intallation, one can use the function

#filexist = exists($Exact_FileName);

If it exists, then #filexist would be 0. But if I don't have the exact file name because the file on the server may have suffixes such as date time, then is there a way to find such files. For example I am looking for files beginning with "ABC" but the files on the server could be "ABC_123". Is there a SQR function for that?

Thank you.

Daniel

the Exists function only seems to be able to search for a file with the exact name including exact extension. It can't seem to be able to search for files with a starting string.

Upvotes: 0

Views: 264

Answers (1)

Bob
Bob

Reputation: 1055

Using the idea from Bobby's comment, I put this together, which works on Windows, but can be modified to work in Linux if needed.

begin-program
    let $comspec = getenv('COMSPEC')
    let $cmd = $comspec || ' /c dir /b ABC*.* > fileList.txt'
    call system using $cmd #error wait
    if #error ! returns non-zero if error
        show 'command error'
        stop
    end-if
    if exists('fileList.txt') ! returns zero if exists
        show 'file does not exist'
        stop
    end-if
    open 'fileList.txt' as 1 for-reading record=512
    while not #end-file
        read 1 into $abc_file:512
        if length($abc_file) ! skips blank at end
            show $abc_file
            ! do what you want with each file here...
        end-if
    end-while
    close 1
end-program

Upvotes: 0

Related Questions