1
現在,我寫了這個邏輯..從創建訂單中的目錄獲取文件?
def get_file_names
@files = []
Find.find("#{BACKUP_FILE_DIR}") do |path|
file_stat = File.stat path
@files << {
:name => File.basename(path,".*"),
:mtime => file_stat.mtime,
:path => path
}
end
@files.delete_at(0)
@files = @files.sort_by { |file| file[:mtime] }
@file_names = []
@files.each do |f|
@file_names << [f[:name],f[:path]]
end
end
我怎麼能改善這個方法?
看到這個問題:http://stackoverflow.com/q/4739967/570156 – Elad 2011-03-29 13:23:39
獲取文件夾名稱..文件夾內沒有文件名.. >> files_sorted_by_time = Dir ['/ db_backups']。sort_by {| f | File.ctime(f)} => [「/ db_backups」] – 2011-03-29 13:48:07
嘗試Dir ['/ db_backups/*'] :) – Elad 2011-03-29 13:55:29