use perl to get file type ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use perl to get file type ?
# 1  
Old 10-26-2007
use perl to get file type ?

Can anybody please tell me how can I determine whether a file is SYMBOLIC LINK, using the stat() function ?

So far I have this:

my @attrs = stat($fileName);
my $mode = $attrs[2];

What next ?
# 2  
Old 10-26-2007
For symbolic links, you should use lstat() to test rather than stat().

Code:
#!/usr/bin/perl -w

use Fcntl ":mode"; 

my @files = ("/etc/rc5.d/S99rc.local", "users.ini");

foreach (@files) {
	my @attrs = lstat($_); 
	print (S_ISLNK($attrs[2])?"$_: Is a Link\n":"$_: Not a Link\n");
}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

2. Shell Programming and Scripting

[solved] File type error (not a regular file)

Hi friend, i have written script as below to check the file existance. but i got error path="/k/p1100/users/jewel/Output" FILENAME=`ls -lrt $path/*HT|tail -1|cut -d "/" -f 8` if ; then echo "$FILENAME is available " chmod 755 $path/$FILENAME /usr/bin/scp... (0 Replies)
Discussion started by: Jewel
0 Replies

3. Shell Programming and Scripting

How can i use switches type arguments for subroutines in perl

i want to call subroutines in perl like: sub temp { ---- some code ----- } temp(-switchName, value1, --switchName2, value2) Like i know getoptions::Long is there for command line switches type arguments. So i want to know for subroutine type arguments. (1 Reply)
Discussion started by: Navrattan Bansa
1 Replies

4. Shell Programming and Scripting

what is the default return type of localtime() in perl?

Hi, I have given like this to get the time of the sub routine. my $start = localtime(); print "\n start time: $start \n"; Output start time: Fri Apr 29 01:01:31 2011 I want to know what is the format of the time. I am not able to follow is is HH:MM:SS or MM:HH:SS os... (2 Replies)
Discussion started by: vanitham
2 Replies

5. Shell Programming and Scripting

Perl variable type assessment

Hello experts, How we can find out,that what is type of a scalar variable? i.e a scalar var contain a number or a string. Thanks in advance. (8 Replies)
Discussion started by: Zaxon
8 Replies

6. Shell Programming and Scripting

Perl data type checking

I am using perl 5.8.0. I need to check some values to see it they are floats. Our system does not have Data::Types so I can't use is_float. Is there something else that I can use? The only thing in Data is Dump.pm. I am not allowed to download anything to our system so I have to use what I have.... (3 Replies)
Discussion started by: ajgwin
3 Replies

7. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

8. Shell Programming and Scripting

how to get type of variable in perl

hello all how can i get the type of variable in perl like typeof(var); in javascript for instance ? to know if the variable is int or string ? (2 Replies)
Discussion started by: umen
2 Replies

9. Shell Programming and Scripting

determine file type with perl

Hello i will like to know please how can i determine file type inside perl script not using the unix "file" program Thanks allot (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question