Created
February 4, 2016 21:59
-
-
Save rorhug/89ebf449e58261543c45 to your computer and use it in GitHub Desktop.
Create c submission zips for college
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 | |
require 'fileutils' | |
require 'zip' | |
# ====== INSTRUCTIONS ====== # | |
# Stick this script in the folder with your programming set folders (s1, s2 etc.) | |
# Run `gem install rubyzip`. This will allow us to zip things | |
# Change the constants below and execute with ./create_submission.rb | |
# ====== CHANGE THESE ====== # | |
HOME = Dir.home # probably leave this actually... | |
STUDENT_NUMBER = "15508327" # Who are you? | |
ZIPFILE_FOLDER = "#{HOME}/Desktop/" # Where to leave them... | |
SOURCE_FILE_TYPES = %w(c h) | |
# ========================== # | |
folders = Dir["./*"].select {|f| File.directory? f} | |
puts "Create programming submission:" | |
print "Which submission? (#{folders[0, 3].map { |f| f[2, 20] }.join(", ")}...): " | |
submission_folder = gets.chomp | |
abort("Folder doesn't exist...") unless folders.include?("./#{submission_folder}") | |
source_file_paths = Dir["./#{submission_folder}/*.{#{SOURCE_FILE_TYPES.join(",")}}"] | |
zipfile_path = "#{ZIPFILE_FOLDER}/#{STUDENT_NUMBER}#{submission_folder}.zip" | |
FileUtils.rm(zipfile_path, force: true) | |
puts "Creating #{zipfile_path} containing:\n#{source_file_paths.join("\n")}\n" | |
Zip::File.open(zipfile_path, Zip::File::CREATE) do |zipfile| | |
source_file_paths.each do |source_file| | |
zipfile.add("#{STUDENT_NUMBER}#{submission_folder}q#{File.basename(source_file)}", source_file) | |
end | |
# Create file containing this text... | |
# zipfile.get_output_stream("myFile") { |os| os.write "myFile contains just this" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment