Sunday, June 17, 2007

Ruby: Tk, select directory

Just quick code for selecting input/output directory#!/usr/bin/env ruby
require 'tk'
bdir=Tk.chooseDirectory('initialdir'=>'./')
puts bdir

Below an example that takes a directory and lists all txt files that contain string '_data' in their name. Than contents of each such file is copied to one output file ('allData.txt'):#!/usr/bin/env ruby
require 'tk'

bdir=Tk.chooseDirectory('initialdir'=>'./')

fout= open('allData.txt', 'w')

Dir.foreach(bdir) { |x|
next if x !~ /_data/
fpath=bdir+'/'+x
File.open(fpath).each_line {|l| fout << l}
}
fout.close

3 comments:

  1. Anonymous9:57 PM

    Үou actually make іt sеem so
    easy with your ρrеsentаtion but I find
    this mаtter to be really sοmething which I think I would nеver undeгstanԁ.
    It seemѕ tοo сomplex and veгy broad fοr me.
    I am loοκіng forward foг уouг nеxt
    post, Ι will trу tο get the hang оf іt!


    Му web blog :: lose weight

    ReplyDelete
  2. Anonymous3:53 AM

    I blog quite often and I reаlly thank you for уοur іnformаtion.
    Тhe articlе hаs truly peakеd my interеst.
    I am going to take a note оf your blog anԁ keeρ cheсκing foг neω ԁetails about once per wеek.
    I opteԁ іn for your Feed аs wеll.


    Feel fгee to suгf to my website :: credit card debt reduction services debt settlement

    ReplyDelete
  3. Anonymous6:33 PM

    Excellent goods from you, man. I've have in mind your stuff previous to and you're simply
    extremely fantastic. I actually like what you've received here, certainly like what you're
    saying and the way wherein you say it. You are making it entertaining and
    you still care for to keep it smart. I can't wait to learn far more from you. This is really a tremendous website.

    Look at my web blog ... W1.lv

    ReplyDelete