Carlos Mantero wrote:
El lun, 28-02-2005 a las 14:49 +0300, Vladimir D Belousov escribió:"-d /home/user" is a string and not a test of directory.
1) if (-d $DIR_NAME) { .... directory exists };
2)
if((lstat($DIR_NAME))[1] & 0040000) {
.... directory exists and it is the real directory (not the symbolic link)
}else{
... No such directory or it is symbolic link
};
Carlos Mantero wrote:
Hi all,
I'm a begginer in Perl and other programming languages. I want to verify that a directory exists, but I don't know the way tho do it.
Regards.
Hi, I tested the code in my little script but the "if" bucle with the verify of the directory don't work fine, always print 1.
if ("-d /home/user") {
So it would always return true.
So use if (-d "/home/user"){ and you would know the problem.
print"1\n";Also, if you are hard coding the path then you need to quote them
}
if (-d "/home/user"){
if you are using a variable then
if (-d $dir){ would work.
But its always a good practice to quote filenames/directories , even if they are variables.