Created
February 10, 2016 19:08
-
-
Save ccoenen/628d456c34e90a09cd95 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# moves files containing 002 on line 9 to a different directory. | |
require 'fileutils' | |
FileUtils.mkdir_p('with002') | |
FileUtils.mkdir_p('no002') | |
def contains_zero_zero_two?(filename) | |
File.open(filename,'r') do |f| | |
lines = f.each_line.take(9) | |
puts "- #{lines.last}" | |
return lines && lines.last.rstrip.end_with?("002") | |
end | |
end | |
Dir['*.txt'].each do |file| | |
puts "checking #{file}" | |
if contains_zero_zero_two?(file) | |
FileUtils.mv(file, "with002/#{file}") | |
else | |
FileUtils.mv(file, "no002/#{file}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment