Ruby/File Directory/File tests

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

# Comparing two files f and g

test ?-, f, g              # File.identical(f,g)
test ?<, f, g              # File(f).mtime < File(g).mtime
test ?>, f, g              # File(f).mtime > File(g).mtime
test ?=, f, g              # File(f).mtime == File(g).mtime



File tests for two files

Test    Returns Description
?-      Boolean True if file1 and file2 are identical
?=      Boolean True if the modification times of file1 and file2 are equal
?<      Boolean True if the modification time of file1 is prior to that of file2
?>      Boolean True if the modification time of file1 is after that of file2



File Tests method list

Test    Returns     Meaning
?A      Time        Last access time for file1
?b      Boolean     True if file1 is a block device
?c      Boolean     True if file1 is a character device
?C      Time        Last change time for file1
?d      Boolean     True if file1 exists and is a directory
?e      Boolean     True if file1 exists
?f      Boolean     True if file1 exists and is a regular file
?g      Boolean     True if file1 has the \CF{setgid} bit set (false under NT)
?G      Boolean     True if file1 exists and has a group ownership equal to the caller"s group
?k      Boolean     True if file1 exists and has the sticky bit set
?l      Boolean     True if file1 exists and is a symbolic link
?M      Time        Last modification time for file1
?o      Boolean     True if file1 exists and is owned by the caller"s effective uid
?O      Boolean     True if file1 exists and is owned by the caller"s real uid
?p      Boolean     True if file1 exists and is a FIFO
?r      Boolean     True if file1 is readable by the effective uid/gid of the caller
?R      Boolean     True if file1 is readable by the real uid/gid of the caller
?s      Int/nil     If file1 has nonzero size, return the size; otherwise return nil
?S      Boolean     True if file1 exists and is a socket
?u      Boolean     True if file1 has the setuid bit set
?w      Boolean     True if file1 exists and is writable by the effective uid/gid
?W      Boolean     True if file1 exists and is writable by the real uid/gid
?x      Boolean     True if file1 exists and is executable by the effective uid/gid
?X      Boolean     True if file1 exists and is executable by the real uid/gid
?z      Boolean     True if file1 exists and has a zero length



Testing single files

test ?e, "/usr/bin/ruby"   # File.exist?("/usr/bin/ruby")
test ?f, "/usr/bin/ruby"   # File.file?("/usr/bin/ruby")
test ?d, "/usr/bin/ruby"   # File.directory?("/usr/bin/ruby")
test ?r, "/usr/bin/ruby"   # File.readable?("/usr/bin/ruby")
test ?w, "/usr/bin/ruby"   # File.writeable?("/usr/bin/ruby")
test ?M, "/usr/bin/ruby"   # File.mtime("/usr/bin/ruby")
test ?s, "/usr/bin/ruby"   # File.size?("/usr/bin/ruby")