Check that file exists: Difference between revisions
Content added Content deleted
(Python example; Re-Ordered languages) |
|||
Line 35: | Line 35: | ||
==[[Perl]]== |
==[[Perl]]== |
||
[[Category:Perl]] |
[[Category:Perl]] |
||
use File::Spec::Functions qw(catfile rootdir); |
|||
#!/usr/bin/perl |
|||
# here |
|||
sub isFileExists($) { |
|||
⚫ | |||
my ($filename) = @_; |
|||
⚫ | |||
return -e $filename; |
|||
# root dir |
|||
} |
|||
⚫ | |||
sub test($$) { |
|||
print -d catfile rootdir, 'docs'; |
|||
my ($type, $filename) = @_; |
|||
print "The following " . $type . " called " . $filename . |
|||
(isFileExists($filename) ? " exists." : " not exists."); |
|||
} |
|||
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/"; |
|||
test("file", "input.txt"); |
|||
test("file", $FileSeperator . "input.txt"); |
|||
test("directory", "docs"); |
|||
test("directory", $FileSeperator ."docs". $FileSeperator); |
|||
exit; |
|||
# Short version |
|||
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/"; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
print -e $FileSeperator.'docs'.$FileSeperator; |
|||
==[[Pop11]]== |
==[[Pop11]]== |