Skip to content

Instantly share code, notes, and snippets.

@nullcookies
Forked from lbvf50mobile/add_licence_script.rb
Created December 26, 2019 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullcookies/61a5fb0c38f8123b9c0152f8a8d8ce56 to your computer and use it in GitHub Desktop.
Save nullcookies/61a5fb0c38f8123b9c0152f8a8d8ce56 to your computer and use it in GitHub Desktop.
Licence script for @lazylead
# 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