-
-
Save nullcookies/61a5fb0c38f8123b9c0152f8a8d8ce56 to your computer and use it in GitHub Desktop.
Licence script for @lazylead
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
# Help for @lazylead | |
licence_file_path = "test_licence.txt" | |
file_name_teplate = /.+\.txt$/ | |
dir_path = 'one' | |
puts "Licence file: #{licence_file_path}\nFile name template: #{file_name_teplate.inspect}\nDirpath: #{dir_path}\nLicence text:\n" | |
p licence_text = File.read(licence_file_path) | |
stack = [dir_path] | |
while !stack.empty? | |
dir = stack.pop | |
Dir.entries(dir).each{|name| | |
next if /^\.+$/ === name | |
new_name = "#{dir}/#{name}" | |
if File.directory?(new_name) | |
stack.unshift(new_name) | |
elsif file_name_teplate === new_name | |
data = File.read(new_name) | |
File.open(new_name, 'w') { |file| file.write(licence_text+data) } | |
puts "ADD: #{new_name}" | |
else | |
puts "SKIP: #{new_name}" | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment