Check that file exists: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (→{{header|REXX}}: fixed case of directory) |
(Add NetRexx implementation) |
||
Line 719: | Line 719: | ||
IO.Put(Fmt.Bool(FileExists("/docs")) & "\n"); |
IO.Put(Fmt.Bool(FileExists("/docs")) & "\n"); |
||
END FileTest.</lang> |
END FileTest.</lang> |
||
=={{header|NetRexx}}== |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref symbols binary |
|||
runSample(arg) |
|||
return |
|||
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
|||
method isExistingFile(fn) public static returns boolean |
|||
ff = File(fn) |
|||
fExists = ff.exists() & ff.isFile() |
|||
return fExists |
|||
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
|||
method isExistingDirectory(fn) public static returns boolean |
|||
ff = File(fn) |
|||
fExists = ff.exists() & ff.isDirectory() |
|||
return fExists |
|||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|||
method runSample(arg) private static |
|||
parse arg files |
|||
if files = '' then files = 'input.txt F docs D /input.txt F /docs D' |
|||
loop while files.length > 0 |
|||
parse files fn ft files |
|||
select case(ft.upper()) |
|||
when 'F' then do |
|||
if isExistingFile(fn) then ex = 'exists' |
|||
else ex = 'does not exist' |
|||
say 'File '''fn'''' ex |
|||
end |
|||
when 'D' then do |
|||
if isExistingDirectory(fn) then ex = 'exists' |
|||
else ex = 'does not exist' |
|||
say 'Directory '''fn'''' ex |
|||
end |
|||
otherwise do |
|||
if isExistingFile(fn) then ex = 'exists' |
|||
else ex = 'does not exist' |
|||
say 'File '''fn'''' ex |
|||
end |
|||
end |
|||
end |
|||
return |
|||
</lang> |
|||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |