Created
May 10, 2017 13:24
-
-
Save nning/6c374d9c3f3774e522dea8e63e8a3fa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# ./move.rb <source_dir> <target_dir> | |
# | |
# Renames files in target_dir according to source_dir | |
require 'fileutils' | |
dir1 = File.expand_path(ARGV[0]) | |
dir2 = File.expand_path(ARGV[1]) | |
dir1_list = Dir.glob(dir1 + '/*.jpg').sort | |
dir2_list = Dir.glob(dir2 + '/*.svg').sort | |
dir1_list.each_with_index do |file1, i| | |
source = dir2_list[i] | |
next unless source | |
target = File.basename(file1).gsub(/(\.[a-z]*)$/, '') + File.extname(source) | |
# p source, target | |
FileUtils.mv(source, target, verbose: true) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# ./pad.rb <dir> | |
# | |
# Searches for numbers in filenames and pads occurances | |
# 1-foo.rb -> 001-foo.rb | |
require 'fileutils' | |
files = ARGV.map { |arg| Dir.glob(arg) }.flatten | |
files.each do |file| | |
n = file.match(/([0-9]*)/)[1] | |
k = n.rjust(3, '0') | |
target = file.gsub(n, k) | |
# p file, target | |
FileUtils.mv(file, target, verbose: true) if n != k | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment