static public Method

File.ftype(p1)

File.ftype(file_name)    string

Identifies the type of the named file; the return string is one of ``file’’, ``directory’’, ``characterSpecial’’, ``blockSpecial’’, ``fifo’’, ``link’’, ``socket’’, or ``unknown’’.

File.ftype("testfile")            #=> "file"
File.ftype("/dev/tty")            #=> "characterSpecial"
File.ftype("/tmp/.X11-unix/X0")   #=> "socket"

Source Code

/*
*  call-seq:
*     File.ftype(file_name)   => string
*  
*  Identifies the type of the named file; the return string is one of
*  ``<code>file</code>'', ``<code>directory</code>'',
*  ``<code>characterSpecial</code>'', ``<code>blockSpecial</code>'',
*  ``<code>fifo</code>'', ``<code>link</code>'',
*  ``<code>socket</code>'', or ``<code>unknown</code>''.
*     
*     File.ftype("testfile")            #=> "file"
*     File.ftype("/dev/tty")            #=> "characterSpecial"
*     File.ftype("/tmp/.X11-unix/X0")   #=> "socket"
*/

static VALUE
rb_file_s_ftype(klass, fname)
   VALUE klass, fname;
{
   struct stat st;

   SafeStringValue(fname);
   if (lstat(StringValueCStr(fname), &st) == -1) {
       rb_sys_fail(RSTRING(fname)->ptr);
   }

   return rb_file_ftype(&st);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.