Posted By

chrisaiv on 11/11/09


Tagged

file dir ruby


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

collegeimprovements


Ruby: Directory Class Methods


 / Published in: Ruby
 

  1. puts File.dirname(__FILE__)
  2.  
  3. #Keeps track of where you are at this moment, it might change often
  4. puts Dir.pwd
  5. #Change Directory
  6. #puts Dir.chdir( File.join('', '') )
  7. #An array of info within the directories
  8. puts Dir.entries('.')
  9. #Code block of files within a directory
  10. Dir.entries('.').each do |entry|
  11. print entry + ": "
  12. if File.file?(entry) && File.readable?(entry)
  13. File.open(entry, 'r') do |file|
  14. puts file.gets
  15. end
  16. else
  17. puts
  18. end
  19. end
  20.  
  21. Dir.foreach("."){ |entry| puts entry }
  22.  
  23. Dir.mkdir('temp_directory')
  24. Dir.delete('temp_directory')

Report this snippet  

You need to login to post a comment.