Skip to content

Instantly share code, notes, and snippets.

@gsampaio
Created January 10, 2018 17:19
Show Gist options
  • Save gsampaio/30129ae6d74e0a14738baebf6a5db2fe to your computer and use it in GitHub Desktop.
Save gsampaio/30129ae6d74e0a14738baebf6a5db2fe to your computer and use it in GitHub Desktop.
Find duplicated swift files in a folder
#!/usr/bin/env ruby
def check(folder)
swift_files = Dir.glob("#{folder}/**/*").select { |file| file.end_with? "swift" }
fileForPaths = {}
for file in swift_files
fileName = file.split('/').last
# If we find a file with the same name we add the path
if fileForPaths[fileName]
fileForPaths[fileName] = [fileForPaths[fileName]] + [file]
else
fileForPaths[fileName] = [file]
end
end
fileForPaths.each do |file, paths|
if paths.count > 1
puts "File #{file} contains multiple paths:"
paths.each do |path|
puts path
end
end
end
end
# Script execution
if ARGV.count != 1
puts "Usage: ruby clean_up.rb folder"
exit(1)
else
check(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment