Skip to content

Instantly share code, notes, and snippets.

@robertwahler
Last active August 1, 2016 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertwahler/64c9c1fc52702a13212f32e9a5ffd1d0 to your computer and use it in GitHub Desktop.
Save robertwahler/64c9c1fc52702a13212f32e9a5ffd1d0 to your computer and use it in GitHub Desktop.
Empty folders, #git, & #unity3d don't mix. Git doesn't track empty folders, why does @Unity3D?
module BasicUnity
class Code < Thor
namespace :code
include Thor::Actions
desc "prune", "Remove empty folders and Unity meta files that point to empty folders"
method_option "dry-run", :type => :boolean, :desc => "Show what will happen but don't 'rmdir' or 'rm'"
def prune(folder=nil)
# bash version, requires GNU find
#
# dry-run
# cmd = "find ./Assets -type d -empty -exec echo '{}' \; -exec echo '{}.meta' \;"
# run(cmd)
#
# for real
# cmd = "find ./Assets -type d -empty -exec rmdir '{}' \; -exec rm '{}.meta' \;"
# run(cmd)
#
folder = ASSETS_FOLDER unless folder
Dir.glob(File.join(folder, "**", "*")).select do |d|
File.directory?(d)
end.reverse_each do |d|
if ((Dir.entries(d) - %w[ . .. ]).empty?)
puts d
Dir.rmdir(d) unless options["dry-run"]
meta = "#{d}.meta"
if File.exist?(meta)
puts meta
File.delete(meta) unless options["dry-run"]
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment