Skip to content

Instantly share code, notes, and snippets.

@landaire
Last active December 16, 2015 05:38
Show Gist options
  • Save landaire/5385478 to your computer and use it in GitHub Desktop.
Save landaire/5385478 to your computer and use it in GitHub Desktop.
Monitors a directory for new MP3 files and moves them to a different directory
require 'fileutils'
DOWNLOADS_PATH = '/Users/lander/Downloads'
while true
Dir.foreach(DOWNLOADS_PATH) do |entry|
next if !(entry =~ /.mp3$/i)
begin
FileUtils.mv(File.join(DOWNLOADS_PATH, entry), '/Users/lander/ext_music')
puts "Moved: #{File.join(DOWNLOADS_PATH, entry)}}"
rescue
puts "Couldn't move: #{File.join(DOWNLOADS_PATH, entry)}"
end
# Wait 30 seconds before the next iteration
sleep(30)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment