Skip to content

Instantly share code, notes, and snippets.

@quwubin
Created March 22, 2015 14:58
Show Gist options
  • Save quwubin/e75048d206bc760d1d66 to your computer and use it in GitHub Desktop.
Save quwubin/e75048d206bc760d1d66 to your computer and use it in GitHub Desktop.
List all the files with suffix .csv (e.g.) in directory "./" (e.g.)
#!/usr/bin/env ruby
require "find"
def get_opts
require 'trollop'
opts = Trollop::options do
version "#{File.basename($PROGRAM_NAME)} 1.0.0 (c) 2014 Wubin Qu"
banner <<-EOS
List all the files with suffix .csv (e.g.) in directory "./" (e.g.)
Usage:
#{File.basename($PROGRAM_NAME)} [options]
EOS
opt :dir, "e.g. /home, /opt/, ./ etc.", type: :string, required: true
opt :suffix, "e.g. .csv, .fasta etc.", type: :string, required: true
opt :out, "Concatenate the contents into Out file.", type: :string, required: true
end
opts
end
if $0 == __FILE__
opts = get_opts
File.open(opts.out, "a") do |oh|
Find.find(opts.dir) do |file|
next unless file.end_with?(opts.suffix)
File.foreach(File.join(opts.dir, file)) do |line|
oh.write(line)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment