Check that file exists: Difference between revisions

no edit summary
No edit summary
Line 5:
=={{header|Ada}}==
This example should work with any Ada 95 compiler.
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
 
procedure File_Exists is
Line 21:
Put_Line (Boolean'Image (Does_File_Exist ("input.txt" )));
Put_Line (Boolean'Image (Does_File_Exist ("\input.txt")));
end File_Exists;</adalang>
This example should work with any Ada 2005 compiler.
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
with Ada.Directories; use Ada.Directories;
 
Line 42:
Print_Dir_Exist ("docs");
Print_Dir_Exist ("/docs");
end File_Exists;</adalang>
 
=={{header|C}}==
{{works with|POSIX}}
<lang c>#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Line 56:
printf("no file lol");
return 0;
}</clang>
 
=={{header|Clojure}}==
Line 120:
 
=={{header|Java}}==
<lang java>import java.io.File;
public class FileExistsTest {
public static boolean isFileExists(String filename) {
Line 137:
test("directory", File.separator + "docs" + File.separator);
}
}</javalang>
 
=={{header|MAXScript}}==
Line 148:
 
=={{header|OCaml}}==
<lang ocaml>Sys.file_exists "input.txt";;
Sys.file_exists "docs";;
Sys.file_exists "/input.txt";;
Sys.file_exists "/docs";;</ocamllang>
 
=={{header|PHP}}==
<lang php>if (file_exists('input.txt')) echo 'input.txt is here right by my side';
if (file_exists('docs' )) echo 'docs is here with me';
if (file_exists('/input.txt')) echo 'input.txt is over there in the root dir';
if (file_exists('/docs' )) echo 'docs is over ther in the root dir';</phplang>
 
=={{header|Perl}}==
<lang perl>use File::Spec::Functions qw(catfile rootdir);
# here
print -e 'input.txt';
Line 166:
# root dir
print -e catfile rootdir, 'input.txt';
print -d catfile rootdir, 'docs';</perllang>
 
'''Without a Perl Module'''
Line 218:
The ''os.path.exists'' method will return True if a path exists False if it does not.
 
<lang python>import os
 
os.path.exists("input.txt")
os.path.exists("/input.txt")
os.path.exists("docs")
os.path.exists("/docs")</pythonlang>
 
=={{header|Raven}}==
Line 233:
 
=={{header|Ruby}}==
<lang ruby>File.exist?("input.txt")
File.exist?("/input.txt")
File.exist?("docs")
File.exist?("/docs")</rubylang>
 
=={{header|Smalltalk}}==