내가 찾아 폴더에서 가장 오래된 AVI 파일을 삭제하는 루비 스크립트를 작성하기 위해 노력했습니다 오래된 AVI 파일을 삭제합니다. 나는 나머지 힘든 시간을 보내고있어,찾아 재귀
require 'fileutils'
stat = Sys::Filesystem.stat("/")
mb_available = stat.block_size * stat.blocks_available/1024/1024
#if there is less than 130MB free
if mb_available < 130000
require 'find'
movie_file_paths = []
#grab all the files in the folder
Find.find('/Users/jody/Movies') do |path|
movie_file_paths << path if /.*\.avi/.match(path) != nil
end
end
그러나 : 나는 아주 가까운 script in Python을 발견, 내가 가진 루비 솔루션에 자신을 좋은 시작을 얻었다. 어떤 도움을 주시면 감사하겠습니다!
편집 :
이 솔루션이었다
movie_file_paths = []
Dir.glob("/Users/jody/Movies/**/*.avi").each { |file| movie_file_paths << file if File.file? file }
movie_file_paths.sort_by {|f| File.mtime(f)}
deleteme = movie_file_paths.first
난 그냥 솔루션을 보았다 'movie_file_paths.sort_by {| f | File.mtime (f)}''movie_file_paths' 배열을 수정하지 않습니다. 새로운 정렬 된 배열을 반환합니다. 당신은 수행해야합니다 '영화 = movie_file_paths.sort_by를 {| f를 | 내가 나가서 설명하자면 NameError를 얻을 = movies.first' – rohit89