Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Ruby Programming/Reference/Objects/IO/File

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

File The file class is typically used for opening and closing files, as well as a few methods like deleting them and stat'ing them. If you want to manipulate a file, not open it, also check out the Pathname class, as well as the FileUtils class. To create a directory you'll need to use the Dir.mkdir method. File#chmod Here's how to do the equivalent of "chmod u+x filename" File.class_eval do def self.addmod(flags, filename) themode=stat(filename).mode | flags chmod(themode, filename) end end Although there's no error checking and the return value could probably be something better (like themode). So after defining that, your 'u+w' would be: @File.addmod(0200, 'filename')@ from http://www.ruby-forum.com/topic/196999#new File#grep This is actually Enumerable#grep, and I believe it just works piece-wise, like File.each_line{|l|yield l if l=~ /whatever/ } File.join This is useful for combining objects that aren't (or might not be) strings into a path. See here.