Sha256: 1d4d7b588302b20285ceca2a8080859148cc18db3c7be5df2d3860dfa2fe89e3

Contents?: true

Size: 491 Bytes

Versions: 10

Compression:

Stored size: 491 Bytes

Contents

module Eddy
  module Util
    # Delete all files from a folder; returns number of deleted files.
    #
    # Fails if the folder contains any symlinks.
    #
    # @param path [String] Path to the folder.
    # @return [Integer]
    def self.clean_folder(path)
      dir = File.expand_path(path)
      return 0 unless Dir.exist?(dir)
      children = Dir.entries(dir).select { |f| File.file?(File.join(dir, f)) }
      deleted = File.unlink(*children)
      return deleted
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eddy-0.10.0 lib/eddy/util/clean_folder.rb
eddy-0.9.2 lib/eddy/util/clean_folder.rb
eddy-0.9.1 lib/eddy/util/clean_folder.rb
eddy-0.9.0 lib/eddy/util/clean_folder.rb
eddy-0.8.4 lib/eddy/util/clean_folder.rb
eddy-0.8.3 lib/eddy/util/clean_folder.rb
eddy-0.8.2 lib/eddy/util/clean_folder.rb
eddy-0.8.1 lib/eddy/util/clean_folder.rb
eddy-0.8.0 lib/eddy/util/clean_folder.rb
eddy-0.7.0 lib/eddy/util/clean_folder.rb