From: Arup Rakshit Date: 2013-02-01T17:10:58+09:00 Subject: Re: Save a file by clicking on a link Joel Pearson wrote in post #1094173: > 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}" ================================= I think below should work also: Dir.chdir("C:/Documents and Settings/peter/My Documents/userdata/Rubydownloads") do until Dir.glob('**/*.part*')[0] != [] sleep 0.1 end But also confused - is this the optimized one? Or could it be more better with a more bit of engineering? end -- Posted via http://www.ruby-forum.com/.