Anonymous user
Check that file exists: Difference between revisions
m
Fixed lang tags.
m (→{{header|PHP}}: s/ther/there/) |
m (Fixed lang tags.) |
||
Line 179:
=={{header|C++}}==
{{libheader|boost}}
<lang cpp>#include "boost/filesystem.hpp"
#include <string>
#include <iostream>
Line 204 ⟶ 203:
testfile("/input.txt");
testfile("/docs");
}</lang>▼
▲</lang>
=={{header|C sharp|C#}}==
Line 217 ⟶ 215:
=={{header|Clojure}}==
<lang lisp>(import '(java.io File))▼
▲(import '(java.io File))
(defn kind [filename]
Line 234 ⟶ 231:
(look-for "/input.txt")
(look-for "docs")
(look-for "/docs")</lang>
</lang>▼
=={{header|Common Lisp}}==
Line 260 ⟶ 256:
=={{header|D}}==
<lang d>import std.file, std.path: sep;
void verify(string name) {
Line 273 ⟶ 268:
// check in root
verify(sep~"input.txt"); verify(sep~"docs");
▲}</lang>
</lang>▼
=={{header|DOS Batch File}}==
Line 283 ⟶ 277:
=={{header|E}}==
▲}</lang>
=={{header|Forth}}==
=={{header|Fortran}}==
Line 306 ⟶ 300:
Cannot check for directories in Fortran
<lang fortran>
Actually, f90,f95 are able to deal with directory staff:
<lang fortran>
=={{header|Haskell}}==
=={{header|J}}==
<lang j>
=={{header|Java}}==
Line 378 ⟶ 372:
=={{header|Logo}}==
{{works with|UCB Logo}}
<lang logo>show file? "input.txt
show file? "input.txt▼
show file? "/input.txt
show file? "docs
show file? "/docs</lang>
Alternatively, one can set a file prefix used for subsequent file commands.
<lang logo>setprefix "/
▲show file? "input.txt</lang>
=={{header|MAXScript}}==
=={{header|Modula-3}}==
Line 457 ⟶ 447:
=={{header|Pop11}}==
Note that the above literally checks for existence. Namely sys_file_exists returns true if file exists but can not be read.
Line 466 ⟶ 456:
The only sure method to check if file can be read is to try to open it. If one just wants to check if file is readable the following may be useful:
The above works but is not the only way or the best way to check status of a file in Pop11. There is a very general procedure sys_file_stat that allows interrogation of a file or directory. The full documentation can be seen in the online documentation (search for sys_file_stat):
Line 517 ⟶ 507:
=={{header|Raven}}==
<lang raven>
=={{header|Ruby}}==
Line 533 ⟶ 523:
=={{header|Slate}}==
<lang slate>(File newNamed: 'input.txt') exists
(File newNamed: '/input.txt') exists
(Directory root / 'input.txt') exists
(Directory newNamed: 'docs') exists
(Directory newNamed: '/docs') exists</lang>
=={{header|Smalltalk}}==
Line 545 ⟶ 533:
[[Squeak]] has no notion of 'current directory' because it isn't tied to the shell that created it.
<lang smalltalk>
In [[GNU Smalltalk]] instead you can do:
<lang smalltalk>
Using ''exists'' in the third and fourth case will return true for directories too.
Line 584 ⟶ 572:
=={{header|Toka}}==
<lang
=={{header|UNIX Shell}}==
=={{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") }
Line 605 ⟶ 592:
// 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}}==
Line 612 ⟶ 598:
{{works with|Visual Basic .NET|9.0+}}
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
|