]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/filesystem.rb
b44e52ce3979506a82155a9db9ac658257c6b19a
[mailshears.git] / lib / common / filesystem.rb
1 class Filesystem
2 # Convenience methods for working with the filesystem. This class
3 # only provides static methods, to be used analogously to the File
4 # class (for example, File.directory?).
5
6
7 # Return whether or not the given path begins with a dot (ASCII
8 # period).
9 #
10 # @param path [String] the path whose first character you want to check.
11 #
12 # @return [Boolean] whether or not *path* begins with an ASCII period.
13 #
14 def self.begins_with_dot?(path)
15 return (path[0..0] == '.')
16 end
17
18
19 # Get a list of all real subdirectories of the given directory.
20 #
21 # @param dir [String] the directory whose subdirectories you want.
22 #
23 # @return [Array<String>] a list of subdirectories of *dir*, not
24 # including the pseudo-directories "." and ".." (the current/parent
25 # directories).
26 #
27 def self.get_subdirs(dir)
28 subdirs = []
29
30 Dir.open(dir) do |d|
31 d.each do |entry|
32 relative_path = File.join(dir, entry)
33 if File.directory?(relative_path) and not self.begins_with_dot?(entry)
34 subdirs << entry
35 end
36 end
37 end
38
39 return subdirs
40 end
41
42 end