How to resolve the algorithm Check that file exists step by step in the COBOL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Check that file exists step by step in the COBOL programming language
Table of Contents
Problem Statement
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
Optional criteria (May 2015): verify it works with:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Check that file exists step by step in the COBOL programming language
Source code in the cobol programming language
identification division.
program-id. check-file-exist.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 skip pic 9 value 2.
01 file-name.
05 value "/output.txt".
01 dir-name.
05 value "/docs/".
01 unusual-name.
05 value "Abdu'l-Bahá.txt".
01 test-name pic x(256).
01 file-handle usage binary-long.
01 file-info.
05 file-size pic x(8) comp-x.
05 file-date.
10 file-day pic x comp-x.
10 file-month pic x comp-x.
10 file-year pic xx comp-x.
05 file-time.
10 file-hours pic x comp-x.
10 file-minutes pic x comp-x.
10 file-seconds pic x comp-x.
10 file-hundredths pic x comp-x.
procedure division.
files-main.
*> check in current working dir
move file-name(skip:) to test-name
perform check-file
move dir-name(skip:) to test-name
perform check-file
move unusual-name to test-name
perform check-file
*> check in root dir
move 1 to skip
move file-name(skip:) to test-name
perform check-file
move dir-name(skip:) to test-name
perform check-file
goback.
check-file.
call "CBL_CHECK_FILE_EXIST" using test-name file-info
if return-code equal zero then
display test-name(1:32) ": size " file-size ", "
file-year "-" file-month "-" file-day space
file-hours ":" file-minutes ":" file-seconds "."
file-hundredths
else
display "error: CBL_CHECK_FILE_EXIST " return-code space
trim(test-name)
end-if
.
end program check-file-exist.
You may also check:How to resolve the algorithm Egyptian division step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Empty directory step by step in the Java programming language
You may also check:How to resolve the algorithm State name puzzle step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Hostname step by step in the REXX programming language
You may also check:How to resolve the algorithm ABC problem step by step in the Action! programming language