Last active
December 22, 2015 02:19
-
-
Save DriftwoodJP/6402900 to your computer and use it in GitHub Desktop.
wp-login.php をリネームするスクリプト。
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
# 初期設定 | |
dir = '/home/<your_id>/public_html/www/<your_wp_dir>/' | |
filename = 'wp-login.php' | |
size = 12 | |
original_file = dir + filename | |
# 指定されたディレクトリに、指定されたファイルがあるか探す | |
if File.exist?(original_file) | |
# あれば リネームする | |
rename = [*1..9, *'A'..'Z', *'a'..'z'].sample(size).join + '_' | |
puts 'found', original_file | |
File.rename(original_file, dir + rename + filename) | |
else | |
# なければ "*_ファイル名" を探してファイル名を戻す | |
rename_file = Dir.glob(dir + '*_' + filename) | |
puts 'found', "#{rename_file[0]}" | |
File.rename(rename_file[0], original_file) | |
end | |
# 変換結果を表示する | |
result = Dir.glob(dir + '*' + filename) | |
puts 'result', result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment