Skip to content

Instantly share code, notes, and snippets.

@aledalgrande
Last active November 22, 2017 20:02
Show Gist options
  • Save aledalgrande/b3cb880058bfd95ebe8e to your computer and use it in GitHub Desktop.
Save aledalgrande/b3cb880058bfd95ebe8e to your computer and use it in GitHub Desktop.
Flatten your iTunes folder keeping artist names in the filename with Ruby: change /Volumes/Backup/iTunes to whatever destination folder you want
ruby -e 'require "fileutils";Dir.glob("./**/*").reject { |d| File.directory?( d ) }.map { |f| [f, "/Volumes/Backup/iTunes/#{File.dirname(f).gsub(/([^\.])\//, "#{$1}-")}-#{File.basename(f)}"] }.map { |f| FileUtils.cp(f[0], f[1], verbose: true) }'
@aledalgrande
Copy link
Author

To run it:

cd ~/Music/iTunes/iTunes\ Media/Music
ruby -e 'require "fileutils";Dir.glob("./**/*").reject { |d| File.directory?( d )  }.map { |f| [f, "/Volumes/Backup/iTunes/#{File.dirname(f).gsub(/([^\.])\//, "#{$1}-")}-#{File.basename(f)}"] }.map { |f| FileUtils.cp(f[0], f[1], verbose: true) }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment