2

Test if the file is NOT a directory in Perl

 2 years ago
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.
neoserver,ios ssh client

Test if the file is NOT a directory in Perl

advertisements

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

I have a file created by an OCR program which I'm trying to access after is being created. In my code I'm checking if the file exists. If I check like this: If File.Exists("C:\inetpub\wwwroot\usbtest\Portals\0\uploads\" + sNewFileName) Then the

When trying to create a file in the C directory, but the file is not created

I have been searching for hours and hours now and cannot figure out why this is not working. I want to create a file in C, in a directory I created, but the file is not being created. Here is the relevant code pertaining to making the directory and c

.htaccess redirects to root when the file is not found

i have a. .htaccess file which looks like below (ps not mine, i think it belongs to Joomla): Now something or bad programming images link to "somefolder/folder/image.png" instead of "/somefolder/folder/image.png" (mind the / in the beg

The file is not created / opened when used with opening

I am using Flask and testing some code in Python. I am trying to store in a log file a Flask request and a string every time a post is done. This is my code: from flask import Flask, render_template, request from vsearch import search4letters app = F

Unable to load bulk because the file could not be opened. Operating System Error Code 3

I'm trying to set up a Stored Procedure as a SQL Server Agent Job and it's giving me the following error, Cannot bulk load because the file "P:\file.csv" could not be opened. Operating system error code 3(failed to retrieve text for this error.

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?

Our Application is build on Spring framework and it is hosted on WAS 6.1. It was designed for the Internet Explorer 6 (as the users using IE 6). It is opening a pdf file through AJAX communication through the controller. In the background it calls a

How do I create required image files when the file is not found?

For example, if I have a file http://site.com/images/bird.jpg When I go http://site.com/images/bird-200px-width.jpg the server will say "file not found". When the server determines the file is not found, is there a way to check the /images/ dire

How to verify that a path is an existing regular file and not a directory?

One script is used to exchange file information amongst teams. It is used as: $ share.py -p /path/to/file.txt The argument checking ensures that /path/to/file.txt exists and has the correct permissions: #[...] # ensure that file exists and is readabl

Check if the file does not exist or the permission has been denied C

How do I check if a file does not exist or it exists but I do not have permission to read it? I know I can use stuff like perror() or strerror(errno) to print messages, but if I want a check that I can handle like this, how do I do that: if (not exis

if [`ls $ op_file`]; then returns true even if the file is not found

#!/bin/bash echo "Enter the o/p file name" read op_file echo "Enter the count" read count echo "OP filename : " echo $op_file if [ `ls $op_file` ]; then echo "O/P file found" else exit 0 fi I'm trying to check wheth

Windows: copy a file until the file does not exist

I want to use a Windows batch file in to copy a file (myfile0001.bdg) from one specific directory to another. But I want to check if the file in the target directory exists and if the answer is yes, increment the file with 0001 and check again if the

move_uploaded_file returns true but the file does not appear in the folder

I have a couple of scripts that worked fine on another server. Now that I have moved everything on to a new server, the file does not appear in the destination folder. The strange thing is that move_uploaded_file returns true. Also, I printed the pos

& ldquo; The file could not be opened. & quot; C ++ fstream

Code : int question_3() { fstream hardware("hardware.dat" , ios::binary | ios::in | ios::out); if (!hardware) { cerr << "File could not be opened." << endl; exit(1); } HardwareData myHardwareData; for (int counter = 1; coun

Symfony - The file could not be found

Entity have nullable=true. Form have required = false. HTML generated havent any required. When I leave file input I got error: The file could not be found. to be honest I have no idea where should I looking for... ;) public function updateAction(Req

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK