Test

Ruby code posted by kareem
created at 14 Nov 09:51

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env ruby
require 'fileutils'
def delete_empty(path= ARGV[0])
  Dir.foreach(path) do |all_directories|
    full_path = File.join(path,all_directories)
    if File.directory?(full_path)
      full_path.each_line do |all|
        next if all == '..' || all == '.'
        if Dir["#{all}/*"].empty?
          FileUtils.rmtree(all)
          puts "#{all} Deleted"
        end
      end
    end
  end
end
puts "Usage: #{__FILE__} dir " if ARGV.empty?
delete_empty
485 Bytes in 2 ms with coderay