Created
March 25, 2013 23:34
-
-
Save farktronix/5241882 to your computer and use it in GitHub Desktop.
Replace an iTunes Library with one song. Use at your own risk!
This file contains hidden or 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 | |
require 'fileutils' | |
include FileUtils::Verbose | |
$rickRollFile="/Volumes/Media/.RickRoll.mp3" | |
def rickRollDir(sourceDir, destDir) | |
for filename in Dir.entries(sourceDir) | |
next if filename=~/\.\.?$/ | |
sourcePath = File.join(sourceDir, filename) | |
destPath = File.join(destDir, filename) | |
fstat = File.stat(sourcePath) | |
case fstat.ftype | |
when "file" | |
if (filename=~/\.xml$/ || filename=~/iTunes Library$/) | |
copy(sourcePath, destPath) | |
next | |
end | |
if filename=~/\.m(p3|4a)$/ | |
sourcePath = $rickRollFile | |
end | |
printf("Linking %s to %s\n", sourcePath, destPath) | |
begin | |
File.symlink(sourcePath, destPath) | |
rescue SystemCallError | |
end | |
when "directory" | |
printf("Creating dir: %s\n", destPath) | |
makedirs(destPath) | |
rickRollDir(sourcePath, destPath) | |
end | |
end | |
end | |
rickRollDir("/Users/sucker/Music", "/Users/sucker/RRMusic") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment