Test if the file is NOT a directory in Perl
source link: https://www.codesd.com/item/test-if-the-file-is-not-a-directory-in-perl.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Test if the file is NOT a directory in Perl
I'm aware you can test if a file is a directory using:
if(-d $filename)
but how can you test if it's not a directory?
Have you thought of trying the following?
if (! -d $filename) ...
The result of -d
is, after all, something that can be treated as a boolean value, hence the logical not operator !
will work fine.
And, if you're after something more specific than "not a directory", see here. There are quite a few things that aren't directories that it sometimes doesn't make sense to treat as regular files.
Keep in mind that's assuming you've already validated that the filename exists. If you do a ! -d
on a non-existent filename, it will return true.
It's a philosophical matter as to whether you consider a non-existent thing to be "not a directory" but, if you want to ensure it exists as well, you can use ! -d
in conjunction with -e
, something like:
if ((-e $filename) && (! -d $filename)) ...
Related Articles
The code indicates that the file does not exist, but exists
When trying to create a file in the C directory, but the file is not created
.htaccess redirects to root when the file is not found
The file is not created / opened when used with opening
Unable to load bulk because the file could not be opened. Operating System Error Code 3
Get the following message when opening a PDF & ldquo; Internet can not download & hellip; Xyz from abc.com The file could not be written to cache & rdquo; In IE?
How do I create required image files when the file is not found?
How to verify that a path is an existing regular file and not a directory?
Check if the file does not exist or the permission has been denied C
if [`ls $ op_file`]; then returns true even if the file is not found
Windows: copy a file until the file does not exist
move_uploaded_file returns true but the file does not appear in the folder
& ldquo; The file could not be opened. & quot; C ++ fstream
Symfony - The file could not be found
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK