class RBT::RemoveEmptyDirectories
Public Class Methods
new( commandline_arguments = ARGV, run_already = true )
click to toggle source
Public Instance Methods
determine_base_directory()
click to toggle source
obtain_all_directories()
click to toggle source
#¶ ↑
obtain_all_directories
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_empty_directories.rb, line 62 def obtain_all_directories # ======================================================================= # # @directories will hold the directories that will be removed. # They will, however had, only be removed when they are empty. # ======================================================================= # @directories = Dir["#{@base_directory}*"].select {|entry| File.directory? entry }.map {|entry| rds(entry) } end
remove_empty_directories(i = @directories)
click to toggle source
#¶ ↑
remove_empty_directories
¶ ↑
This will remove empty directories.
However had, we will not remove directories that start with a ‘/’ character and have only one ‘/’ in total.
#¶ ↑
# File lib/rbt/utility_scripts/remove_empty_directories.rb, line 126 def remove_empty_directories(i = @directories) i.each {|entry| entry = rds(entry) # ===================================================================== # # Check whether the directory is empty or whether it is not: # ===================================================================== # if Dir.empty?(entry) shall_we_remove_this_directory = true msg_to_the_user = "The directory at `#{sdir(entry)}` is empty.".dup if entry.start_with?('/') and entry.count('/') == 1 shall_we_remove_this_directory = false else msg_to_the_user << ' It will be removed next.' end opne msg_to_the_user if shall_we_remove_this_directory remove_directory(entry) # Only remove it if it is not something like '/run'. end end } end
reset()
click to toggle source
run()
click to toggle source
set_base_directory(i = return_pwd)
click to toggle source
#¶ ↑
set_base_directory
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_empty_directories.rb, line 46 def set_base_directory(i = return_pwd) case i # ======================================================================= # # === :current_working_directory # ======================================================================= # when :current_working_directory i = return_pwd end i = i.dup if i.frozen? i << '/' unless i.end_with? '/' @base_directory = i end
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
Invocation example for this method:
remove-empty-directories --help
#¶ ↑
# File lib/rbt/utility_scripts/remove_empty_directories.rb, line 80 def show_help e e 'The argument given to this class will specify the target directory' e 'that is to be used. By default this will be the current working '\ 'directory.' e exit end