Sha256: 8fdb8be6da48cae304bc624168d34989b15968ee3ddca396be50eed39fe36c98

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

#!/usr/bin/env ruby
require 'fileutils'
require 'find'

module XcodeDirectories
	DERIVED_DATA = "#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData/*"
	ARCHIVES = "#{File.expand_path('~')}/Library/Developer/Xcode/Archives/*"
end

def dir_size(dir_path)
  total_size = 0
  Find.find(dir_path) do |path|
      if FileTest.directory?(path)
        if File.basename(path)[0] == ?.
          Find.prune
        else
          next
        end
      else
        total_size += FileTest.size(path)
      end
    end
    total_size
end

trash_size = 0
XcodeDirectories.constants.each do |dir|
	files = Dir.glob(XcodeDirectories.const_get(dir))
	if files.empty?
		next
	end
	files.each do |folder|
		trash_size += dir_size(folder)
		FileUtils.rm_rf(folder)
	end
end

if trash_size > 0
	puts "Deleted all files from #{XcodeDirectories.constants[0]} and #{XcodeDirectories.constants[1]}"
	puts "\n#{trash_size} bytes deleted"
else
	puts "The directories are empty"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xcode_trash_remover-1.0.0 bin/xcodert