Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/bagit/file.rb

Class Method Summary collapse

Class Method Details

.clean(file_name) ⇒ Object

Clean out all the empty dirs



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bagit/file.rb', line 4

def File.clean(file_name)

  if File.directory? file_name
    # clean all subdirs
    subdirs = Dir.entries(file_name).select { |p| File.directory?(File.join(file_name, p)) }
    subdirs.reject! { |p| %w{. ..}.include? p }
    subdirs.each { |sd| File.clean File.join(file_name, sd) }

    # if its empty then delete it
    contents = Dir.entries(file_name).reject { |p| %w{. ..}.include? p }
    Dir.delete file_name if contents.empty?
  end
  
end