Last active
September 7, 2017 01:35
-
-
Save liuxd/605cc66b406da30b4332 to your computer and use it in GitHub Desktop.
[Win2unix.rb] Replace the windows' line breaks into unix line breaks.
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
# -*- encoding : utf-8 -*- | |
module Win2unix | |
@@file_list = [] | |
def self.tidy path, ext = 'txt' | |
get_all_files path, ext | |
@@file_list.each do |file| | |
handle file | |
end | |
@@file_list.size | |
end | |
def self.get_all_files path, ext = 'txt' | |
Dir.glob("#{path}/*") do |file| | |
if File.directory? file | |
get_all_files file | |
else | |
if File.extname(file) == '.' + ext | |
@@file_list.push file | |
end | |
end | |
end | |
end | |
def self.handle file | |
origin = IO.binread file | |
handled = origin.gsub /\r\n/, "\n" | |
f = File.new file, 'w' | |
f.print handled | |
f.close | |
end | |
end | |
# end of this file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage