Last active
September 7, 2017 01:33
-
-
Save liuxd/55cb39eaaaccb06751ecca3f4547fbc8 to your computer and use it in GitHub Desktop.
[Blog Fixer] 将原来的博客md文件去掉头部信息。
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 | |
| def traverse(filepath) | |
| if filepath.include? '.git' or filepath.include? '.DS_Store' or filepath.include? 'README' | |
| return | |
| end | |
| if File.directory?(filepath) | |
| # puts "Dirs:" + filepath | |
| Dir.foreach(filepath) do |filename| | |
| if filename != "." and filename != ".." | |
| traverse(filepath + "/" + filename) | |
| end | |
| end | |
| else | |
| origin_file = File.basename(filepath) | |
| new_file = origin_file[11, origin_file.length - 1] | |
| dir = File.dirname filepath | |
| lines = IO.readlines(filepath) | |
| content = lines[6, lines.length - 1].join() | |
| file = File.new dir + '/' + new_file, 'w+' | |
| file.syswrite content | |
| File.delete filepath | |
| end | |
| end | |
| path=ARGV[0] | |
| traverse path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment