From: Joel Pearson Date: 2013-01-29T18:26:58+09:00 Subject: Re: Save a file by clicking on a link Arup Rakshit wrote in post #1094152: > Is it possible to pause the next set of statements until the download is > not being finished? I need to rewrite this at some point, it was a quick-fix and doesn't currently have failsafes. Anyway, this is what I'm using: ____________ @download_directory = "#{Dir.pwd}/RubyDownloads" @current_downloads = Dir.entries( @download_directory ) def wait_for_download #Find the newest file difference = [1,2] until difference.size == 1 difference = Dir.entries(@download_directory) - @current_downloads sleep 0.1 end file_name = difference.first puts "Found new file: #{file_name}" new_size = 0 current_size = -1 #Wait for file size to stop changing until current_size == new_size current_size = File.size("#{@download_directory}\\#{file_name}") #puts "current file size: #{current_size}" sleep 0.1 new_size = File.size("#{@download_directory}\\#{file_name}") #puts "new file size: #{new_size}" sleep 0.1 end end ____________ -- Posted via http://www.ruby-forum.com/.