Skip to content

Instantly share code, notes, and snippets.

@inz
Last active August 29, 2015 14:09
Show Gist options
  • Save inz/e59a55d49bae4cb77182 to your computer and use it in GitHub Desktop.
Save inz/e59a55d49bae4cb77182 to your computer and use it in GitHub Desktop.
DSLab 14W Rename Submission Files from Harvest
#!/usr/bin/env ruby
require 'fileutils'
MAPPING='dslab14-account-mapping.txt'
FOLDER=ARGV.first || 'DSLab-Harvest-1237'
TARGET=File.join('processed')
Dir.mkdir(TARGET) rescue nil
# Map users to immatriculation numbers.
users = {}
File.open(MAPPING, 'r') do |file|
file.each do |line|
parts = line.split
next if parts.length < 5
user = parts[0]
immatrnr = parts[4]
users[user] = immatrnr
end
end
Dir.new(FOLDER).each do |entry|
user=entry.split('_').first
next unless users.include?(user)
base_path = File.join(FOLDER, entry)
submission_filename = Dir.glob(File.join(base_path, "*.zip")).first
next unless submission_filename
# Rename to <immatr.nr>.zip
puts "Copying from: #{submission_filename} to: #{File.join(TARGET, "#{users[user]}.zip")}"
FileUtils.cp submission_filename, File.join(TARGET, "#{users[user]}.zip")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment