Check that file exists: Difference between revisions
Content added Content deleted
Line 25: | Line 25: | ||
} |
} |
||
} |
} |
||
==[[Perl]]== |
|||
[[Category:Perl]] |
|||
#!/usr/bin/perl |
|||
sub isFileExists($) { |
|||
return -e $_[0]; |
|||
} |
|||
sub test($$) { |
|||
print "The following " . $_[0] . " called " . $_[1] . |
|||
(isFileExists($_[1]) ? " exists." : " not exists."); |
|||
} |
|||
test("file", "input.txt"); |
|||
test("file", "/input.txt"); |
|||
test("file", "\\input.txt"); |
|||
test("directory", "docs"); |
|||
test("directory", "/docs/"); |
|||
test("directory", "\\docs\\"); |
|||
exit; |
|||
# Short version |
|||
print -e 'input.txt'; |
|||
print -e '/input.txt'; |
|||
print -e "\\input.txt"; |
|||
print -e 'docs'; |
|||
print -e '/docs/'; |
|||
print -e "\\docs\\"; |