Have you thought of trying the following?
if (! -d $filename) ...
The result of -d
is, after all, something that can be considered as a boolean, therefore a logical operator !
will work fine.
And if you use something more specific than "not a directory", see here . There are many things that are not directories, which sometimes do not make sense to consider as ordinary files.
Keep in mind that if you have already confirmed that the file name exists. If you follow ! -d
! -d
in a nonexistent file name, it will return true.
This is a philosophical question about whether you consider a non-existent thing “not a catalog”, but if you want to provide it, you can use it ! -d
! -d
combined with -e
, something like:
if ((-e $filename) && (! -d $filename)) ...
source share