Check that file exists: Difference between revisions
Content added Content deleted
m (→[[Java]]: Use Java header instead) |
m (Changes over to headers.) |
||
Line 4: | Line 4: | ||
In this task, the job is to verify that a file called "input.txt" and the directory called "docs" exist. This should be done twice: once for the current working directory and once for a file and a directory in the filesystem root. |
In this task, the job is to verify that a file called "input.txt" and the directory called "docs" exist. This should be done twice: once for the current working directory and once for a file and a directory in the filesystem root. |
||
== |
=={{header|C}}== |
||
[[Category:C]] |
|||
#include <sys/types.h> |
#include <sys/types.h> |
||
#include <sys/stat.h> |
#include <sys/stat.h> |
||
Line 17: | Line 16: | ||
} |
} |
||
== |
=={{header|DOS Batch File}}== |
||
[[Category:DOS Batch File]] |
|||
if exist input.txt echo The following file called input.txt exists. |
if exist input.txt echo The following file called input.txt exists. |
||
if exist \input.txt echo The following file called \input.txt exists. |
if exist \input.txt echo The following file called \input.txt exists. |
||
Line 24: | Line 22: | ||
if exist \docs\ echo The following directory called \docs\ exists. |
if exist \docs\ echo The following directory called \docs\ exists. |
||
== |
=={{header|Forth}}== |
||
[[Category:Forth]] |
|||
: .exists ( str len -- ) 2dup file-status nip 0= if type ." exists" else type ." does not exist" then ; |
: .exists ( str len -- ) 2dup file-status nip 0= if type ." exists" else type ." does not exist" then ; |
||
Line 53: | Line 50: | ||
} |
} |
||
== |
=={{header|MAXScript}}== |
||
[[Category:MAXScript]] |
|||
-- Here |
-- Here |
||
doesFileExist "input.txt" |
doesFileExist "input.txt" |
||
Line 62: | Line 58: | ||
(getDirectories "C:\docs").count == 1 |
(getDirectories "C:\docs").count == 1 |
||
== |
=={{header|PHP}}== |
||
[[Category:PHP]] |
|||
// List of files. |
// List of files. |
||
$files = array('./input.txt','./docs','/input.txt','/docs'); |
$files = array('./input.txt','./docs','/input.txt','/docs'); |
||
Line 77: | Line 72: | ||
} |
} |
||
== |
=={{header|Perl}}== |
||
[[Category:Perl]] |
|||
use File::Spec::Functions qw(catfile rootdir); |
use File::Spec::Functions qw(catfile rootdir); |
||
# here |
# here |
||
Line 95: | Line 89: | ||
perl -e 'print -d "/docs", "\n";' |
perl -e 'print -d "/docs", "\n";' |
||
== |
=={{header|Pop11}}== |
||
[[Category:Pop11]] |
|||
sys_file_exists('input.txt') => |
sys_file_exists('input.txt') => |
||
Line 120: | Line 113: | ||
enddefine; |
enddefine; |
||
== |
=={{header|Python}}== |
||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.5 |
'''Interpreter:''' [[Python]] 2.5 |
||
Line 133: | Line 125: | ||
os.path.exists("/docs") |
os.path.exists("/docs") |
||
== |
=={{header|Raven}}== |
||
[[Category:Raven]] |
|||
'input.txt' exists if 'input.txt exists' print |
'input.txt' exists if 'input.txt exists' print |
||
Line 141: | Line 132: | ||
'/docs' isdir if '/docs exists and is a directory' print |
'/docs' isdir if '/docs exists and is a directory' print |
||
=={{header|SmallTalk}}== |
|||
==[[Smalltalk]]== |
|||
[[Category:Smalltalk]] |
|||
"Smalltalk has no notion of 'current directory' because Smalltalk isn't tied to the shell that created it." |
"Smalltalk has no notion of 'current directory' because Smalltalk isn't tied to the shell that created it." |
||
Line 150: | Line 140: | ||
(FileDirectory on: 'c:\') directoryExists: 'docs'. |
(FileDirectory on: 'c:\') directoryExists: 'docs'. |
||
== |
=={{header|Tcl}}== |
||
[[Category:Tcl]] |
|||
Taking the meaning of the task from the DOS example: |
Taking the meaning of the task from the DOS example: |
||
Line 161: | Line 150: | ||
if { [file isdirectory [file nativename /docs]] } { puts "/docs exists and is a directory" } |
if { [file isdirectory [file nativename /docs]] } { puts "/docs exists and is a directory" } |
||
== |
=={{header|Toka}}== |
||
[[Category:Toka]] |
|||
[ "R" file.open dup 0 <> [ dup file.close ] ifTrue 0 <> ] is exists? |
[ "R" file.open dup 0 <> [ dup file.close ] ifTrue 0 <> ] is exists? |
||
Line 170: | Line 158: | ||
" /docs" exists? . |
" /docs" exists? . |
||
== |
=={{header|Visual Basic .NET}}== |
||
[[Category:Visual Basic .NET]] |
|||
'''Platform:''' [[.NET]] |
'''Platform:''' [[.NET]] |