Determining whether direcotry or file 
Author Message
 Determining whether direcotry or file

        Hi,
        I succefully get a file mode information. And
I'd like to check the item is whether file or directory.

        in C, we can just do
                if (mode && FWT_D)

        In perl, How should I do?

        Thank you



Fri, 08 Jan 1999 03:00:00 GMT  
 Determining whether direcotry or file


Quote:
>    I succefully get a file mode information. And I'd like to check
> the item is whether file or directory.

Do you mean this?

   if (-f $filename) {
        print "It's a file.\n";
   } elsif (-d _) {
        print "It's a directory.\n";
   } else {
        print "It's something odd, like maybe a pipe.\n";
   }

If you've stat()ed the file, you can use the mode information to determine
this, but it's probably just as fast and certainly ten times clearer to
use these file test operators. They're documented in the giant perlfunc(1)
man page, under -X.

Hope this helps!

-- Tom Phoenix            http://www.teleport.com/~rootbeer/




Fri, 08 Jan 1999 03:00:00 GMT  
 Determining whether direcotry or file

Quote:

>         Hi,
>         I succefully get a file mode information. And
> I'd like to check the item is whether file or directory.

>         in C, we can just do
>                 if (mode && FWT_D)

>         In perl, How should I do?

>         Thank you

To check if it's a directory you do :

if (-d $file) {  ......

To check if it's a file you do:

if (-f $file) {  ......

(this is on page 120 in the Llama book if you have one)

 - Joe Fernald



Fri, 08 Jan 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Determining whether a process is interactive

2. determining whether a server supports secure authentication

3. Showing contents of a direcotry

4. file upload, determining file type, size, format

5. Determining whether two files are identical... is it reasonable to use Digest::MD5?

6. Checking whether file exists

7. checking whether a file exists

8. How to detect whether STDERR is duped to another file handle

9. Telling Whether a Wildcarded Regular Expression Will Match Any Files

10. Checking whether a file is open or not?

11. How to determine file type of a filehandle?

12. Determine type of file ascii or bin

 

 
Powered by phpBB® Forum Software