Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Perl: Your visual blueprint for building Perl scripts    (ISBN: 0764534785)


 

 List Price: $24.99
 Our Price: $17.49
 Used Price: $14.99

 Release Date: 01 August, 2000
 Manufacturer: John Wiley & Sons (Paperback)
 Sales Rank: 214,778

 Author: Paul Whitehead, Eric Kramer, Ruth Maran Maran









More Info

 File Stats 2001-11-11 01:54:02
  perl 
Category: source:perl:files
Description: An example of file testing in perl.
Platform: unix
Author: detour
Viewed: 5590
Rating: 4.2/5 (24 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
filestats.pl
#!/usr/bin/perl
#
# File stats written by detour@metalshell.com
#
# Example of file testing.
#
# -o $file	true if owned by EUID
# -e $file	exists
# -z $file	zero file
# -s $file	non-zero file, returns size
# -r $file	readable	 
# -w $file	writeable
# -x $file	executable
# -f $file	plain file
# -d $file	directory
# -l $file	symbolic link
# -p $file	named pipe or FIFO
# -S $file	socket
# -b $file	block special file
# -c $file	character special file
# -T $file	text file
# -B $file	binary file
# -u $file	setuid
# -g $file	setgid
# -k $file	sticky
# -t $file	true if opened to a tty
# -M $file	age in days since modified
# -A $file	age in days since last accessed
# -C $file	age in days since inode changed
#
# http://www.metalshell.com
#


unless($ARGV[0]) {
  die "Usage: $0 filename\n";
}


print "File info for: $ARGV[0]\n";
print "---------------------------\n";

if (-f $ARGV[0]) { 
  print "File: Yes.\n";
} else {
  print "File: No.\n";
}

if (-d $ARGV[0]) {
  print "Directory: Yes.\n";
} else {
  print "Directory: No.\n";
}

if (-r $ARGV[0]) {
  print "Readable: Yes.\n";
} else {
  print "Reabable: No.\n";
}

if (-w $ARGV[0]) {
  print "Writable: Yes.\n";
} else {
  print "Writable: No. \n";
}

printf "Last modified: %f days ago\n", -M $ARGV[0];
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?