I want to check if pass file exist and there is no fail file in certain path. Is there any operator for file not exist?
example path:
x.pass
y.fail
my $filepath = "path/to/file/";
if (-e "$filepath/*pass" && <*fail not exist>){
#do something
}
I want to check if pass file exist and there is no fail file in certain path. Is there any operator for file not exist?
example path:
x.pass
y.fail
my $filepath = "path/to/file/";
if (-e "$filepath/*pass" && <*fail not exist>){
#do something
}
stat
/-e
gets information about a file. It returns false if there's an error, including if it doesn't exist. It returns error ENOENT
if the file doesn't exist.
if ( !-e $path ) {
die( "`$path` doesn't exist\n" ) if $!{ENOENT}; # Optional.
die( "Can't stat `$path`: $!\n" );
}
or
if ( !stat( $path ) ) {
die( "`$path` doesn't exist\n" ) if $!{ENOENT}; # Optional.
die( "Can't stat `$path`: $!\n" );
}
Note that you ask how to check if a file exists. If you're asking about globs as your example suggests, you already know how to do that.