From: "J.Hawkesworth" Date: 2002-11-09T00:55:01+09:00 Subject: Re: How do I get a '\'? Thanks for all the help and suggestions. I have something that works (in a simple beginner sort of fashion) now. See below if you are interested. All the best, Jon # secure_stick.rb # Purpose: copies the contents of a usb memory stick to a backup area on the hard disk # Runs under: Windows # ruby 1.66 (I must upgrade!) # Code: Jon Hawkesworth # History: 08 November 2002 got it working #~ # Things To Do: #~ rescues in appropriate areas #~ handle the memory stick not being there #~ determine the drive where the stick is programmatically?? #~ ## Read stick root and backup root from an ini file?? #~ ## Get stick root, backup root from user if ini file not found #~ check results # THINGS YOU WILL NEED TO CHANGE stick_root='G:'; backup_area='C:' + File::Separator + 'stick_backup' + File::Separator temp_backup_area=File::Separator + 'stick_backup_old' # END OF THINGS YOU WILL NEED TO CHANGE require 'tk' require 'ftools' require 'find' # this method straight out of 'ruby way' - thanks Hal def delete_all(dir) Dir.foreach(dir) do |e| next if [".",".."].include? e fullname = dir + File::Separator + e if FileTest::directory?(fullname) delete_all(fullname) else File.delete(fullname) end end Dir.delete(dir) end # work out what is on the memory stick dirs = [] files = [] Find.find(stick_root) {|f| if FileTest.directory?(f) dirs.push(f) else files.push(f) end } # rename the existing backup dir and make a new empty backup dir File.rename(backup_area, temp_backup_area) Dir.mkdir(backup_area) # create whatever dirs are needed dirs.each {|d| to = d.sub(/#{stick_root}/, backup_area) if (! FileTest::directory?(to)) File.makedirs(to) end } # iterate through the list of files on the memory stick, changing the path and copying the file to the backup area files.each {|f| to = f.sub(/#{stick_root}/, backup_area) File.install(f, to) } # Should really check that the above worked before removing the last backup. # now that the backup proper has taken place, get rid of the old version of the backup delete_all(temp_backup_area) # and finally display the report time = Time.now # define a window root = TkRoot.new { title "Backup memory stick" } # define a label to say what has happened TkLabel.new(root) { text "Memory stick back up completed at #{time}\nA total of #{files.length} files were processed"; pack { padx 5 ; pady 5; side 'left' } } # define a button with which to say I've had enough of looking at this message TkButton.new(root) { text "Ok" command proc { exit } pack('side'=>'left', 'padx'=>1, 'pady'=>1) } # run the app Tk.mainloop __END__ secure_stick.rb -----Original Message----- From: Eric Hodel [mailto:drbrain@segment7.net] Sent: 04 November 2002 20:11 To: ruby-talk ML Subject: Re: How do I get a '\'? J.Hawkesworth (J.Hawkesworth@talis.com) wrote: > Hi, > > interestingly I also get: > > irb(main):045:0> p File::Separator > "/" > nil File::ALT_SEPARATOR = '\' -- Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 _____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Control Centre. For further information visit http://www.star.net.uk/stats.asp _____________________________________________________________________ Any views or personal opinions expressed within this email may not be those of Talis Information Ltd. The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.