OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/help/move_files.rb

38 lines
1016 B

5 years ago
#!/usr/bin/env ruby
require 'fileutils'
Dir.glob('**/*.md').each do |source_file|
folder = File.dirname(source_file)
filename = File.basename(source_file, '.md')
next if filename == 'README'
target_folder = File.join(folder, filename)
target = File.join(target_folder, 'README.md')
FileUtils.mkdir_p target_folder
FileUtils.mv source_file, target
end
FileUtils.mkdir_p('unused-images')
Dir.glob('**/*.{png,jpg,gif}').each do |image_file|
5 years ago
image_filename = File.basename(image_file)
contained = `rg -l '#{image_filename}'`.lines.map(&:chomp)
if contained.empty?
FileUtils.mv image_file, 'unused-images'
elsif contained.length > 1
warn "Skipping #{image_file} as used in more than one: #{contained.join(", ")}"
else
target_folder = File.dirname contained.first
target_file = File.join(target_folder, image_filename)
if image_file == target_file
puts "Image is already at #{target_file}"
else
FileUtils.mv image_file, target_folder
end
end
end