File listing and copying between directories


/ Published in: Ruby
Save to your folder(s)

Rake task - Copies files from one directory to another in a batch of 50 files, giving 15 seconds break between each batch.


Copy this code and paste it in your HTML
  1. desc "Lists all files in a directory"
  2. task :list do
  3. Dir.chdir(C_DIR)
  4. fs = Dir.glob('**/*.JPG')
  5. count, similar_files = 0
  6. initial = 50
  7. fs.each do |f|
  8. if File.file? f
  9. puts "#{count += 1} -> Copying #{f} to #{REMOTE_DIR}"
  10. unless File.exist?("#{REMOTE_DIR}#{f.to_s}")
  11. File.copy(old_file, new_file, verbose => true)
  12. else
  13. similar_files += 1
  14. end
  15. if count == initial
  16. initial += 50
  17. sleep(15)
  18. end
  19. end
  20. end
  21. puts "Number of Similar files: #{similar_files}"
  22. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.