require 'date'require 'MFile.rb'class MFolder < ActiveRecord::Base has_many :MFile belongs_to :MFolder set_table_name "MFolder" def MFolder.findChildren(params = nil) root = params[:root] parrent = params[:parrent] rootname = File.basename(root).split("/").last if parrent then rootname = parrent + "/" + rootname end if (not root =~ /^.*\/$/) then root = root + "/" end rootmdate = File.stat(root).mtime rootfol = MFolder.find_by_path(root) if rootfol.nil? then rootfol = MFolder.create(:name => rootname, :path => root, :date => rootmdate, :MFolder_id => params[:parrent_id]) puts "Added MFolder '#{rootname}' from '#{root}'\n" end d = Dir.new(root) d.each do |path| if (path == root) then next end if (path =~ /^\.+$/) then next end# if parrent then# path = root + "/" + path# else path = root + path# end name = File.basename(path).split("/").last# if parrent then name = parrent + "/" + name end mdate = File.stat(path).mtime if(File.directory?(path)) then findChildren(:root => path, :parrent => rootname, :parrent_id => rootfol.id) else if(not name =~ /\.avi|\.mpg/) then next end if(name =~ /\.!ut/) then next end f = MFile.find_by_name_and_path(name, path) if f.nil? then f = MFile.create(:name => name, :path => path, :date => mdate, :plays => 0, :MFolder_id => rootfol.id) puts "Added MFile '#{name}' in '#{rootfol.name}'\n" end if(f.date < File.stat(f.path).mtime) then f.date = File.stat(f.path).mtime end end end endend