Last active
February 27, 2018 20:16
-
-
Save ddd1600/75ea57e27298976849e6b70c06e59544 to your computer and use it in GitHub Desktop.
zip individual files inside of folder
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
require 'shellwords' | |
require 'highline/import' | |
target_ext = ask("file extension to target (excluding the period)?") | |
output_ext = ask("output file extension? press enter to default to zip") | |
output_ext = output_ext.blank? ? "zip" : output_ext | |
files = Dir.glob("*.#{target_file_extension}") | |
files.each do |f| | |
puts "-----\nworking with '#{f}'" | |
f = File.basename(f) | |
basename = f.split(".")[0..-2].join | |
puts "extensionless basename = '#{basename}'" | |
shellsafebasename = Shellwords.escape(basename) | |
puts "escaped path for shell = '#{shellsafebasename}'" | |
shellcmd = "zip -r #{shellsafebasename}.#{output_ext} #{Shellwords.escape(f)}" | |
puts "trying to run this command: '#{shellcmd}'" | |
`#{shellcmd}` | |
end# of files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment