]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/filesystem.rb
Fix ownership issues in the agendav.sql test schema.
[mailshears.git] / lib / common / filesystem.rb
1 # Convenience methods for working with the filesystem. This class
2 # only provides static methods, to be used analogously to the File
3 # class (for example, <tt>File.directory?</tt>).
4 #
5 class Filesystem
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 return subdirs if not File.directory?(dir)
30
31 Dir.open(dir) do |d|
32 d.each do |entry|
33 relative_path = File.join(dir, entry)
34 if File.directory?(relative_path) and not self.begins_with_dot?(entry)
35 subdirs << entry
36 end
37 end
38 end
39
40 return subdirs
41 end
42
43 end