Check that file exists: Difference between revisions

Added Algol 68
(Code added for FreeBASIC)
(Added Algol 68)
Line 69:
 
</lang>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses the Algol 68G specific "file is directory" procedure to test for the existence of directories.
<lang algol68># Check files and directories exist #
 
# check a file exists by attempting to open it for input #
# returns TRUE if the file exists, FALSE otherwise #
PROC file exists = ( STRING file name )BOOL:
IF FILE f;
open( f, file name, stand in channel ) = 0
THEN
# file opened OK so mst exist #
close( f );
TRUE
ELSE
# file cannot be opened - assume it does not exist #
FALSE
FI # file exists # ;
 
# print a suitable messages if the specified file exists #
PROC test file exists = ( STRING name )VOID:
print( ( "file: "
, name
, IF file exists( name ) THEN " does" ELSE " does not" FI
, " exist"
, newline
)
);
# print a suitable messages if the specified directory exists #
PROC test directory exists = ( STRING name )VOID:
print( ( "dir: "
, name
, IF file is directory( name ) THEN " does" ELSE " does not" FI
, " exist"
, newline
)
);
 
# test the flies and directories mentioned in the task exist or not #
test file exists( "input.txt" );
test file exists( "\input.txt");
test directory exists( "docs" );
test directory exists( "\docs" )</lang>
 
=={{header|Applesoft BASIC}}==
3,048

edits