X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fcommon%2Ffilesystem.rb;h=0c80b59e55f98488a118faf5251e8b1a372af551;hb=5a055eeec92d0b3e81e0acda54ebc09fb5897dcf;hp=72ff901dd1e0dc602369c6a795a13d0164ab30d5;hpb=c6cab6b71770d14dad1115db90a00b990c44a58d;p=mailshears.git
diff --git a/lib/common/filesystem.rb b/lib/common/filesystem.rb
index 72ff901..0c80b59 100644
--- a/lib/common/filesystem.rb
+++ b/lib/common/filesystem.rb
@@ -1,16 +1,37 @@
+# Convenience methods for working with the filesystem. This class
+# only provides static methods, to be used analogously to the File
+# class (for example, File.directory?).
+#
class Filesystem
- def self.begins_with_dot(path)
+ # Return whether or not the given path begins with a dot (ASCII
+ # period).
+ #
+ # @param path [String] the path whose first character you want to check.
+ #
+ # @return [Boolean] whether or not *path* begins with an ASCII period.
+ #
+ def self.begins_with_dot?(path)
return (path[0..0] == '.')
end
+
+ # Get a list of all real subdirectories of the given directory.
+ #
+ # @param dir [String] the directory whose subdirectories you want.
+ #
+ # @return [Array] a list of subdirectories of *dir*, not
+ # including the pseudo-directories "." and ".." (the current/parent
+ # directories).
+ #
def self.get_subdirs(dir)
subdirs = []
+ return subdirs if not File.directory?(dir)
Dir.open(dir) do |d|
d.each do |entry|
relative_path = File.join(dir, entry)
- if (File.directory?(relative_path) and not begins_with_dot(entry))
+ if File.directory?(relative_path) and not self.begins_with_dot?(entry)
subdirs << entry
end
end