Check that file exists: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Alphabets... how do they work?)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 21:
fs:is_dir(‘docs’)
fs:is_dir(‘/docs’)</lang>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 136 ⟶ 137:
.include "../includeARM64.inc"
</lang>
 
=={{header|Ada}}==
This example should work with any Ada 95 compiler.
Line 795 ⟶ 797:
return 0;
}</lang>
 
=={{header|C sharp|C#}}==
 
<lang csharp>using System.IO;
 
Console.WriteLine(File.Exists("input.txt"));
Console.WriteLine(File.Exists("/input.txt"));
Console.WriteLine(Directory.Exists("docs"));
Console.WriteLine(Directory.Exists("/docs"));</lang>
 
=={{header|C++}}==
Line 823 ⟶ 834:
testfile("/docs");
}</lang>
 
=={{header|C sharp|C#}}==
 
<lang csharp>using System.IO;
 
Console.WriteLine(File.Exists("input.txt"));
Console.WriteLine(File.Exists("/input.txt"));
Console.WriteLine(Directory.Exists("docs"));
Console.WriteLine(Directory.Exists("/docs"));</lang>
 
=={{header|Clojure}}==
Line 1,003 ⟶ 1,005:
'\input.txt' doesn't exist
'\docs' doesn't exist</pre>
 
=={{header|DCL}}==
<lang DCL>$ if f$search( "input.txt" ) .eqs. ""
Line 1,408 ⟶ 1,411:
! ...
99 WRITE(Messagebox='!') 'File does not exist. Error message ', ios </lang>
 
=={{header|HolyC}}==
<lang holyc>U0 FileExists(U8 *f) {
if (FileFind(f) && !IsDir(f)) {
Print("'%s' file exists.\n", f);
} else {
Print("'%s' file does not exist.\n", f);
}
}
 
U0 DirExists(U8 *d) {
if (IsDir(d)) {
Print("'%s' directory exists.\n", d);
} else {
Print("'%s' directory does not exist.\n", d);
}
}
 
FileExists("input.txt");
FileExists("::/input.txt");
DirExists("docs");
DirExists("::/docs");</lang>
 
=={{header|i}}==
Line 1,436 ⟶ 1,461:
}</lang>
Note: Icon and Unicon accept both / and \ for directory separators.
 
=={{header|HolyC}}==
<lang holyc>U0 FileExists(U8 *f) {
if (FileFind(f) && !IsDir(f)) {
Print("'%s' file exists.\n", f);
} else {
Print("'%s' file does not exist.\n", f);
}
}
 
U0 DirExists(U8 *d) {
if (IsDir(d)) {
Print("'%s' directory exists.\n", d);
} else {
Print("'%s' directory does not exist.\n", d);
}
}
 
FileExists("input.txt");
FileExists("::/input.txt");
DirExists("docs");
DirExists("::/docs");</lang>
 
=={{header|IDL}}==
Line 1,661 ⟶ 1,664:
{{VI snippet}}<br/>
[[File:Ensure_that_a_file_exists.png]]
 
 
=={{header|Lasso}}==
Line 1,778 ⟶ 1,780:
end
end</lang>
 
=={{header|M2000 Interpreter}}==
Report print proportional text using word wrap, and justification. Can be used to calculate lines, and to render form a line, a number of lines. We can specify the width of the text, and by moving the cursor horizontal we can specify the left margin. This statement can be used to any layer, including user forms and printer page.
Line 1,975 ⟶ 1,978:
echo existsDir "docs"
echo existsDir "/docs"</lang>
 
=={{header|Objective-C}}==
<lang objc>NSFileManager *fm = [NSFileManager defaultManager];
NSLog(@"input.txt %s", [fm fileExistsAtPath:@"input.txt"] ? @"exists" : @"doesn't exist");
NSLog(@"docs %s", [fm fileExistsAtPath:@"docs"] ? @"exists" : @"doesn't exist");</lang>
 
=={{header|Objeck}}==
Line 1,995 ⟶ 1,993:
}
</lang>
 
=={{header|Objective-C}}==
<lang objc>NSFileManager *fm = [NSFileManager defaultManager];
NSLog(@"input.txt %s", [fm fileExistsAtPath:@"input.txt"] ? @"exists" : @"doesn't exist");
NSLog(@"docs %s", [fm fileExistsAtPath:@"docs"] ? @"exists" : @"doesn't exist");</lang>
 
=={{header|OCaml}}==
Line 2,061 ⟶ 2,064:
perl -e 'print -e "/input.txt", "\n";'
perl -e 'print -d "/docs", "\n";'
 
=={{header|Perl 6}}==
<lang perl6>
my $path = "/etc/passwd";
say $path.IO.e ?? "Exists" !! "Does not exist";
 
given $path.IO {
when :d { say "$path is a directory"; }
when :f { say "$path is a regular file"; }
when :e { say "$path is neither a directory nor a file, but it does exist"; }
default { say "$path does not exist" }
}</lang>
 
<code>when</code> internally uses the smart match operator <code>~~</code>, so <code>when :e</code> really does <code>$given ~~ :e</code> instead of the method call <code>$given.e</code>; both test whether the file exists.
 
<lang perl6>
run ('touch', "♥ Unicode.txt");
 
say "♥ Unicode.txt".IO.e; # "True"
say "♥ Unicode.txt".IO ~~ :e; # same
</lang>
 
=={{header|Phix}}==
Line 2,189 ⟶ 2,171:
First line of file D:\_l\tst.txt: Test line 1
File D:\_l\nix.txt not found
</pre>
 
=={{header|Pop11}}==
Line 2,227 ⟶ 2,209:
 
<lang powershell> Test-Path input.txt</lang>
 
 
=={{header|Prolog}}==
Line 2,307 ⟶ 2,288:
(and (file-exists? "input.txt")
(file-exists? "docs")))
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>
my $path = "/etc/passwd";
say $path.IO.e ?? "Exists" !! "Does not exist";
 
given $path.IO {
when :d { say "$path is a directory"; }
when :f { say "$path is a regular file"; }
when :e { say "$path is neither a directory nor a file, but it does exist"; }
default { say "$path does not exist" }
}</lang>
 
<code>when</code> internally uses the smart match operator <code>~~</code>, so <code>when :e</code> really does <code>$given ~~ :e</code> instead of the method call <code>$given.e</code>; both test whether the file exists.
 
<lang perl6>
run ('touch', "♥ Unicode.txt");
 
say "♥ Unicode.txt".IO.e; # "True"
say "♥ Unicode.txt".IO ~~ :e; # same
</lang>
 
Line 2,409 ⟶ 2,412:
["docs", "/docs"].each { |d|
printf "%s is a directory? %s\n", d, File.directory?(d) }</lang>
 
 
=={{header|Run BASIC}}==
Line 2,656 ⟶ 2,658:
return 0;
}</lang>
 
=={{header|Vedit macro language}}==
Vedit allows using either '\' or '/' as directory separator character, it is automatically converted to the one used by the operating system.
<lang vedit>// In current directory
if (File_Exist("input.txt")) { M("input.txt exists\n") } else { M("input.txt does not exist\n") }
if (File_Exist("docs/nul", NOERR)) { M("docs exists\n") } else { M("docs does not exist\n") }
 
// In the root directory
if (File_Exist("/input.txt")) { M("/input.txt exists\n") } else { M("/input.txt does not exist\n") }
if (File_Exist("/docs/nul", NOERR)) { M("/docs exists\n") } else { M("/docs does not exist\n") }</lang>
 
=={{header|Visual Basic .NET}}==
'''Platform:''' [[.NET]]
 
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>'Current Directory
Console.WriteLine(If(IO.Directory.Exists("docs"), "directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists("output.txt"), "file exists", "file doesn't exists"))
 
'Root
Console.WriteLine(If(IO.Directory.Exists("\docs"), "directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists("\output.txt"), "file exists", "file doesn't exists"))
 
'Root, platform independent
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "docs"), _
"directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "output.txt"), _
"file exists", "file doesn't exists"))</lang>
 
=={{header|VBA}}==
Line 2,707 ⟶ 2,681:
End Function
</lang>
 
 
=={{header|VBScript}}==
Line 2,747 ⟶ 2,720:
 
</lang>
 
=={{header|Vedit macro language}}==
Vedit allows using either '\' or '/' as directory separator character, it is automatically converted to the one used by the operating system.
<lang vedit>// In current directory
if (File_Exist("input.txt")) { M("input.txt exists\n") } else { M("input.txt does not exist\n") }
if (File_Exist("docs/nul", NOERR)) { M("docs exists\n") } else { M("docs does not exist\n") }
 
// In the root directory
if (File_Exist("/input.txt")) { M("/input.txt exists\n") } else { M("/input.txt does not exist\n") }
if (File_Exist("/docs/nul", NOERR)) { M("/docs exists\n") } else { M("/docs does not exist\n") }</lang>
 
=={{header|Visual Basic}}==
Line 2,769 ⟶ 2,752:
End Function
</lang>
 
=={{header|Visual Basic .NET}}==
'''Platform:''' [[.NET]]
 
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>'Current Directory
Console.WriteLine(If(IO.Directory.Exists("docs"), "directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists("output.txt"), "file exists", "file doesn't exists"))
 
'Root
Console.WriteLine(If(IO.Directory.Exists("\docs"), "directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists("\output.txt"), "file exists", "file doesn't exists"))
 
'Root, platform independent
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "docs"), _
"directory exists", "directory doesn't exists"))
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "output.txt"), _
"file exists", "file doesn't exists"))</lang>
 
=={{header|Yabasic}}==
10,333

edits