This is similar to the code in watir/cookiemanager.rb
However, i should note that this code has no tests for it and was only put
there as a convenience to users (just like the code below). I suspect that
it also has platform limitations. I don't know enough to recommend one
implementation over the other.
I've been thinking about putting code like this in watir/contrib/* instead.
The idea is that any code could be put here with no warrenty from us. There
are a couple files in watir/* that should probably go there. Plus we could
include more stuff from people on the list.
Another idea would be to farm a page on RubyGarden.org with examples.
Thoughts?
Bret
At 09:17 PM 11/22/2005, Paul Rogers wrote:
>Here is the code to get rid of cookies. Sorry it took so long, had to
>get permission, and then I kept forgetting
>
>It was writtern on Win XP - the paths maybe different for win 2000
>
>It may be possible to add a reg exp or string to limit the domain that
>cookies are deleted
>
>Thanks to Jason Scammell and Neteller for this.
>
># file revision: "$Revision: #0 $"
># Author:: Jason Scammell [EMAIL PROTECTED]
># Purpose: To delete all cookies on the PC
># Date: Oct 24, 2005
>class Dir
> require 'find'
> include Find
> def Dir.visit(dir = '.', files_first = false, &block)
> if files_first
> paths = []
> Find.find(dir) { |path| paths << path }
> paths.reverse_each {|path| yield path}
> else
> Find.find(dir, &block)
> end
> end
> # simulates unix rm -rf command
> def Dir.rm_rf(dir)
>
> Dir.visit(dir, true) do |path|
> if FileTest.directory?(path)
> begin
> Dir.unlink(path)
> rescue # Security Exception for Content.IE
> end
> else
> puts "removing #{ path }"
> begin
> File.unlink(path)
> rescue => e #Security exception index.dat etc.
> puts "Exception " + e
> end
> end
> end
> end
>end
>
>class CookieKiller
> def self.kill()
> dir =CookieKiller.cookie_dir()
> Dir.rm_rf( dir)
> end
> def self.cookie_dir()
> return ENV['HOMEDRIVE'] + '\\' + ENV['HOMEPATH'] + "\\Cookies"
> end
>
>end
>
>
>
># file revision: "$Revision: #0 $"
># Author:: Jason Scammell [EMAIL PROTECTED]
># Purpose: To test the CookieKiller class
># Date: Oct 24, 2005
>
>require '../neteller.rb'
>require 'test/unit'
>class CookieKillerTest < Test::Unit::TestCase
>
> def test_cookie_killer_dir()
>
> cookie_count = get_file_count()
> puts cookie_count -3 # files .,..,index.dat are never deleted.
> CookieKiller.kill()
> delete_count= get_file_count()
> puts delete_count
> assert (get_file_count() ==3)
>
> end
>
> def get_file_count()
> dir = CookieKiller.cookie_dir()
> d = Dir.new(dir)
> count=0
> d.each do |x|
> count = count +1
> end
> return count
> end
>
>end
>
>_______________________________________________
>Wtr-general mailing list
>[email protected]
>http://rubyforge.org/mailman/listinfo/wtr-general
_____________________
Bret Pettichord
www.pettichord.com
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general