Reading, Writing, Removing Files and Directories in Ruby

These aren’t all of them, but I think they are some of the most useful.

# making a directory in another directory that doesn't yet exist...
FileUtils.mkdir_p '/path/to/your/directory/that/doesnt/exist/yet'

# recursively remove a directory and the contents
FileUtils.rm_rf("/path/to/directory/you/want/to/delete")

# write a file from the contents of another file...
File.open("/path/to/the/file.ext", "wb") {|f| f.write(@your_other_file.read)}

Related posts:

  1. Listing Files and Directories with PHP
  2. Recursively Zip a Directory and Files on Linux
  3. Add User Directories to Apache2 Web Server
  4. Rails Paperclip Plugin Options for Attaching Files
  5. Recursively Zip Up a Directory while Excluding Certain Files Based on File Extension Type
This entry was posted in ruby and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>