Created
August 16, 2019 21:49
-
-
Save uilianries/b6a50241ce65f2fdedb2cdaa0034597d to your computer and use it in GitHub Desktop.
Rename All image files
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
import os | |
import magic | |
if __name__ == "__main__": | |
files = [] | |
path = "/home/uilian/Development/conan/docs" | |
# r=root, d=directories, f = files | |
for r, d, f in os.walk(path): | |
for file in f: | |
file_path = os.path.join(r, file) | |
if "image" in magic.from_file(file_path) or \ | |
file.endswith(".png") or \ | |
file.endswith(".jpg"): | |
print(f"Found {file}") | |
if file.startswith("conan-"): | |
continue | |
elif file.startswith("conan_"): | |
new_file = file.replace("conan_", "conan-") | |
new_path = os.path.join(r, new_file) | |
print(f"Rename {file_path} : {new_path}") | |
os.rename(file_path, new_path) | |
command = "find {} -type f -name '*.rst' | xargs sed -i 's/{}/{}/g'".format( | |
path, file.replace(".", r"\."), new_file) | |
os.system(command) | |
else: | |
new_file = "conan-" + file | |
new_path = os.path.join(r, new_file) | |
print(f"Rename {file_path} : {new_path}") | |
os.rename(file_path, new_path) | |
command = "find {} -type f -name '*.rst' | xargs sed -i 's/{}/{}/g'".format( | |
path, file.replace(".", r"\."), new_file) | |
os.system(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried installing the prostgresql database see error.. Help bro
Please help me why this error on the terminal
Sent from my W2 using FastHub