class FolderStash::Folder
A Folder
represents a directory in the filesystem.
Attributes
basename[R]
Basename for the folder.
path[R]
Absolute path for the folder.
Public Class Methods
folders_for_path_segment(root, segment)
click to toggle source
# File lib/folder_stash/folder.rb, line 22 def self.folders_for_path_segment(root, segment) root_folder = Folder.new root segment.inject([root_folder]) do |dirs, dir| path = File.join dirs.last.path, dir dirs << Folder.new(path) end end
Public Instance Methods
count()
click to toggle source
Returns the number of visible files in the folder.
# File lib/folder_stash/folder.rb, line 31 def count entries.count end
create()
click to toggle source
Creates the directory path in the immediate parent.
# File lib/folder_stash/folder.rb, line 36 def create FileUtils.mkdir path unless exist? end
create!()
click to toggle source
Creates the directory path
with all parents.
# File lib/folder_stash/folder.rb, line 41 def create! FileUtils.mkdir_p path unless exist? end
entries(include_hidden: false)
click to toggle source
Returns a list of entries (files or folders) in the folder.
Options¶ ↑
-
include_hidden
-
true
- list visible and hidden entries. -
false
(default) - list only visible entries.
-
# File lib/folder_stash/folder.rb, line 57 def entries(include_hidden: false) children = Dir.children path return children if include_hidden == true children.reject { |entry| entry.start_with? '.' } end
exist?()
click to toggle source
Returns true
if the directory path
exists.
# File lib/folder_stash/folder.rb, line 46 def exist? File.exist? path end