Created
March 22, 2015 14:58
-
-
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.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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