New file script

I set up a file server at home so that I can access my files from any computer in the house. I put new files on the box all the time, and don’t always remember what’s new when I want to grab new songs or put photos online, so I wrote this thing in ruby to run through the files on the drive and make a list of new ones. A cron job runs it once a week. Next on the agenda, I’ll make it email me the list and copy all the new files to my backup drive.
It gives you a total new file count at the end, and some spiffy output to look at while it runs. It also skips those dot files that OS X leaves all over the place.
require 'date'
require 'find'

total_new_files = 0
now = Time.now
a_week_ago = now-(604800)
filename = "newfiles" + Date.today.to_s + ".txt" 

File.open(filename,"w") do |file|
  Find.find("/none/of/your/business") do |f|
    type = case
     when File.file?(f): it = f
     else "?" 
    end

    if it != nil && !(it =~ /DS_Store/i)
      filename = (it.to_s).split(/\//)
      unless filename.last =~ /^\./
        print "." 
        if File.ctime(it) >= a_week_ago
          file << it.to_s + "\n" 
      total_new_files = total_new_files + 1
        end
      end
    end
  end
end
puts "total new files: " + total_new_files.to_s

0 comments