Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # begins file handlers
- class File
- #-----------------------------------------------------------------------------
- # Reads all files in a directory
- #-----------------------------------------------------------------------------
- def self.readAll(dir)
- files = []
- Dir.chdir(dir){ Dir.glob("*"){ |f| files.push(dir+"/"+f) } }
- return files.sort
- end
- #-----------------------------------------------------------------------------
- # Checks for existing directory, gets around non-UNICODE characters
- #-----------------------------------------------------------------------------
- def self.safeDir?(dir)
- ret = false; Dir.chdir(dir) { ret = true } rescue nil
- return ret
- end
- #-----------------------------------------------------------------------------
- # Generates entire file/folder tree from a certain directory
- #-----------------------------------------------------------------------------
- def self.grabAll(dir)
- # sets variables for starting
- files = []
- for file in self.readAll(dir)
- # engages in recursion to read the entire file tree
- files += self.safeDir?(file) ? self.grabAll(file) : [file]
- end
- # returns all found files
- return files
- end
- #-----------------------------------------------------------------------------
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement