Checking for a directory

2003-07-24 Thread Rus Foster
Hi All,
Just trying to work out the code to test if a path is a directory or file.
Looked over the stat function but doesn't quite seem right. Can someone
give me a clue

thanks

Rus

-- 
www: http://jvds.com   | Virtual Servers from just $15/mo
MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
e: [EMAIL PROTECTED]   | FreeBSD  Linux
   10% donation to FreeBSD.org on each purchase

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Checking for a directory

2003-07-24 Thread Marcos . Rebelo
Example Name Result 
-e $a   ExistsTrue if file named in $a exists 
-r $a   Readable  True if file named in $a is readable 
-w $a   Writable  True if file named in $a is writable 
-d $a   Directory True if file named in $a is a directory 
-f $a   File  True if file named in $a is a regular file 
-T $a   Text File True if file named in $a is a text file 

so:
if (-d $filename) {
print '$filename$ is a directory\n;
}





-Original Message-
From: Rus Foster [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 2:39 PM
To: [EMAIL PROTECTED]
Subject: Checking for a directory


Hi All,
Just trying to work out the code to test if a path is a directory or file.
Looked over the stat function but doesn't quite seem right. Can someone
give me a clue

thanks

Rus

-- 
www: http://jvds.com   | Virtual Servers from just $15/mo
MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
e: [EMAIL PROTECTED]   | FreeBSD  Linux
   10% donation to FreeBSD.org on each purchase

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
if ( -d $path ) { print Directory }
elsif ( -f $path ) { print File }
else { print Not exist }

HTH

- Original Message - 
From: Rus Foster [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 8:39 PM
Subject: Checking for a directory


 Hi All,
 Just trying to work out the code to test if a path is a directory or file.
 Looked over the stat function but doesn't quite seem right. Can someone
 give me a clue

 thanks

 Rus

 -- 
 www: http://jvds.com   | Virtual Servers from just $15/mo
 MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
 e: [EMAIL PROTECTED]   | FreeBSD  Linux
10% donation to FreeBSD.org on each purchase

 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Checking for a directory

2003-07-24 Thread Kipp, James
-d $dir #if true than is a dir
-f $file #if true than is a regulare file



 -Original Message-
 From: Rus Foster [mailto:[EMAIL PROTECTED]
 Sent: Thursday, July 24, 2003 8:39 AM
 To: [EMAIL PROTECTED]
 Subject: Checking for a directory
 
 
 Hi All,
 Just trying to work out the code to test if a path is a 
 directory or file.
 Looked over the stat function but doesn't quite seem right. 
 Can someone
 give me a clue
 
 thanks
 
 Rus
 
 -- 
 www: http://jvds.com   | Virtual Servers from just $15/mo
 MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
 e: [EMAIL PROTECTED]   | FreeBSD  Linux
10% donation to FreeBSD.org on each purchase
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Checking for a directory

2003-07-24 Thread Dan Muey
 Hi All,
 Just trying to work out the code to test if a path is a 
 directory or file. Looked over the stat function but doesn't 
 quite seem right. Can someone give me a clue
 
Sure thing:

 if(-d $path) { print $path is adirectory; }
 perldoc -f -d to find out more about file tests

HTH
Dmuey

 thanks
 
 Rus
 
 -- 
 www: http://jvds.com   | Virtual Servers from just $15/mo
 MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
 e: [EMAIL PROTECTED]   | FreeBSD  Linux
10% donation to FreeBSD.org on each purchase
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread wiggins


On Thu, 24 Jul 2003 23:00:17 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

 if ( -d $path ) { print Directory }
 elsif ( -f $path ) { print File }
 else { print Not exist }
 

Not exist is misleading, just because a file is not a 'plain' file or a 'directory' 
does *NOT* indicate non-existence.  Existence should be checked explicitly with the -e 
operator. 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
Yep ! =)

Even though I can't imagine what a path is not file or directory would imply
more then not exist. But I agree to check the existence for a path by -e
is the safest operation.


- Original Message - 
From: [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]; Rus Foster [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 11:06 PM
Subject: Re: Checking for a directory



 
 On Thu, 24 Jul 2003 23:00:17 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

  if ( -d $path ) { print Directory }
  elsif ( -f $path ) { print File }
  else { print Not exist }
 

 Not exist is misleading, just because a file is not a 'plain' file or a
'directory' does *NOT* indicate non-existence.  Existence should be checked
explicitly with the -e operator.

 http://danconia.org

 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread Rus Foster
On Thu, 24 Jul 2003, LI NGOK LAM wrote:

 if ( -d $path ) { print Directory }
 elsif ( -f $path ) { print File }
 else { print Not exist }

 HTH

Cheers all. Think I was trying to be to clever for my own good

RGds

]Rus
-- 
www: http://jvds.com   | Virtual Servers from just $15/mo
MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
e: [EMAIL PROTECTED]   | FreeBSD  Linux
   10% donation to FreeBSD.org on each purchase

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread wiggins

On Thu, 24 Jul 2003 23:20:20 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

 Yep ! =)
 
 Even though I can't imagine what a path is not file or directory would imply
 more then not exist. But I agree to check the existence for a path by -e
 is the safest operation.
 

Since you asked ;-) from perldoc -f -e 

-l  File is a symbolic link.
-p  File is a named pipe (FIFO), or Filehandle is a pipe.
-S  File is a socket.
-b  File is a block special file.
-c  File is a character special file.

-f implies that a file is 'plain' aka not really special in any way. Files come in 
many different flavors not only based on their contents, though this is largely system 
dependent. Most windows and old Mac OS users will go their whole life not knowing 
about these (I said not knowing about and most, not that they don't exist there, 
personally I am not sure they do or don't, but then I don't much care either :-) )...

If you have access to a fairly standard unix system try:

perl -e 'if (-f /dev/tty0) { print File is plain.\n; } else { if (-e /dev/tty0) 
{ print File is not plain, but does exist.\n } }'

The issue was not with whether -f will tell you of non-existence, because it will, but 
by using your 'else' block you were implying non-existence by not being a plain file 
and not a directory, which is an incorrect (strictly speaking) implication.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
Thanks for this great lesson, I will take account for this on my furture =))


- Original Message - 
From: [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, July 25, 2003 12:17 AM
Subject: Re: Checking for a directory


 
 On Thu, 24 Jul 2003 23:20:20 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

  Yep ! =)
 
  Even though I can't imagine what a path is not file or directory would
imply
  more then not exist. But I agree to check the existence for a path by -e
  is the safest operation.
 

 Since you asked ;-) from perldoc -f -e 

 -l  File is a symbolic link.
 -p  File is a named pipe (FIFO), or Filehandle is a pipe.
 -S  File is a socket.
 -b  File is a block special file.
 -c  File is a character special file.

 -f implies that a file is 'plain' aka not really special in any way. Files
come in many different flavors not only based on their contents, though this
is largely system dependent. Most windows and old Mac OS users will go their
whole life not knowing about these (I said not knowing about and most,
not that they don't exist there, personally I am not sure they do or don't,
but then I don't much care either :-) )...

 If you have access to a fairly standard unix system try:

 perl -e 'if (-f /dev/tty0) { print File is plain.\n; } else { if (-e
/dev/tty0) { print File is not plain, but does exist.\n } }'

 The issue was not with whether -f will tell you of non-existence, because
it will, but by using your 'else' block you were implying non-existence by
not being a plain file and not a directory, which is an incorrect (strictly
speaking) implication.

 http://danconia.org




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]