Tagged as file

edit delete favorite
Posted by snipsniper on Nov 29, 2007
Common File methods and modes.
File.join(p1, p2, ... pN)           => "p1/p2/.../pN" platform independent paths
File.new(path, modestring="r")      => file
File.new(path, modenum [, permnum]) => file
IO.readlines(path)                  => array
File.open(fileName, aModeString="r") {|file| block}
File.open(fileName [, aModeNum [, aPermNum ]]) {|file| block}
IO.foreach(path, sepstring=$/) {|line| block}

# Mode Strings
r   # Read-only, starts at beginning of file (default mode).
r+  # Read-write, starts at beginning of file.
w   # Write-only, truncates existing file to zero length or creates a new file for writing.
w+  # Read-write, truncates existing file to zero length or creates a new file for reading and writing.
a   # Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
a+  # Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
b   # (DOS/Windows only) Binary file mode (may appear with any of the key letters listed above).
 
Please submit any bugs/features and report abuse. Thanks!
Spacer
Spacer
Spacer
Top Tags
Spacer