Last active
August 29, 2015 14:16
-
-
Save deadlyfingers/85d512e2a5b7d2caa4f0 to your computer and use it in GitHub Desktop.
Helper script to copy a bunch of images from one source folder to replace/update images within Camtasia project sub-directories.
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/ruby | |
# fileswap.rb v1.0 written by @deadlyfingers | |
# Helper script to copy a bunch of images from one source folder | |
# to replace/update images within Camatasia project sub-directories. | |
# Usage: | |
# ruby fileswap.rb "images-dir" "target-dir" | |
# Example: | |
# ruby fileswap.rb "/Users/david/Pictures/CamtasiaStills" "/Users/david/Movies/Camtasia 2/MyProject.cmproj" | |
# Disclaimer: | |
# All scripts are provided AS IS without warranty of any kind. | |
# Use entirely at your own risk. If unsure always do a backup of your work first. | |
require 'rubygems' | |
require 'fileutils' | |
$dirTarget = "" | |
$acceptedFormats = [".png", ".jpg", ".jpeg", ".gif"] | |
$dirImages = "" | |
$filePointer = 0 | |
$files = [] | |
$imageNames = [] | |
# handle arguements | |
if ( ARGV.length != 2 ) | |
puts "Usage: ruby fileswap.rb \"<images-dir>\" \"<target-dir>\"" | |
puts "Example: ruby fileswap.rb \"/Users/david/Pictures/CamtasiaStills\" \"/Users/david/Movies/Camtasia 2/MyProject.cmproj\"" | |
exit 0 | |
else | |
$dirImages = ARGV[0] | |
$dirTarget = ARGV[1] | |
puts "Copying images from: #{$dirImages} \nto #{$dirTarget}" | |
end | |
# handle target destination cases | |
if File.extname("#{$dirTarget}") == "cmproj" | |
puts "Targeting Camtasia project media directory." | |
$dirDest = "#{$dirTarget}/media" | |
else | |
$dirDest = "#{$dirTarget}" | |
end | |
# given $imageFiles and $imageNames will be in the same order | |
$imageNamesFiles = Dir.glob("#{$dirImages}/*").each do |f| | |
$imageNames << File.basename(f) | |
end | |
Dir.glob("#{$dirDest}/**/*").each do |f| | |
if !File.directory?(f) | |
if $acceptedFormats.include? File.extname("#{f}") | |
basename = File.basename(f) | |
$files << f #basename | |
#puts "#{basename}\n" | |
if $imageNames.include? basename | |
needle = $imageNames.index(basename) | |
puts "##{needle} replaced \"#{basename}\" \n #{$imageNamesFiles[needle]} \n => #{$files[$filePointer]} \n\n" | |
# perform copy and replace files - cp_r(src, dest, options = {}) | |
FileUtils.cp_r("#{$imageNamesFiles[needle]}","#{$files[$filePointer]}") | |
end | |
$filePointer += 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment