Skip to content

Instantly share code, notes, and snippets.

@P-PPPP
Created July 5, 2022 13:02
Show Gist options
  • Select an option

  • Save P-PPPP/c80a453376f690a41f91ad39fb6cffb9 to your computer and use it in GitHub Desktop.

Select an option

Save P-PPPP/c80a453376f690a41f91ad39fb6cffb9 to your computer and use it in GitHub Desktop.
import os , shutil
# step1: Make Structure Tree
files = []
def make_structure_tree(path):
for i in os.listdir(path):
if os.path.isdir(path+"/"+i):
make_structure_tree(path+"/"+i)
else: files.append(path+"/"+i)
make_structure_tree(".")
def Purify_Jvav(name:str)->str:
def exchange_jvav(org:str , posi:list)->str:
def k(s:str)->str:
new = ""
for n in s:
if n == "a": new += "v"
elif n == "A": new += "V"
elif n == "v": new += "a"
elif n == "V": new += "A"
else: new += n
return new
new = org
for _num in range(len(org)):
if _num in posi:
new = new.replace(org[_num:_num+len("jvav")],k(org[_num:_num+len("jvav")]))
return new
jvav_nums = name.lower().count("jvav")
jvav_posis = []
jvav_posis.append(name.lower().find("jvav"))
for i in range(jvav_nums): jvav_posis.append(name.lower().find("jvav",jvav_posis[-1]+1))
jvav_posis.remove(-1)
assert len(jvav_posis) == jvav_nums , "Error: jvav_nums != jvav_posis"
_tmp = exchange_jvav(name , jvav_posis)
return _tmp
def Jvav_Move(org:str , dst:str)->None:
dst = dst.split("/")
dst_str = '/'.join(dst)
for i in range(len(dst) -1):
a = '/'.join(dst[:i+1])
if os.path.exists(a) == False: os.mkdir(a)
shutil.move(org , dst_str)
"""
if not any(dst_str.endswith(i) for i in
["png","jpg","jpeg","gif","nrm","icu","spp","ico","icns","wav",
"pf","sgml","bmp","badAction","good","noEvents","nullComponent","nullDragSource","nullOrigin","ttf"]):
"""
try:
org_jvav_txt = open(dst_str,"r",encoding="utf-8").read()
open(dst_str,"w",encoding="utf-8").write(Purify_Jvav(org_jvav_txt))
except UnicodeDecodeError: print("Error: UnicodeDecodeError")
for i in files:
# Step1: Replace Jvav Path
new = Purify_Jvav(i)
print(f"Replacing Jvav Path: {i} to {new}")
Jvav_Move(i,new)
print(f"Done: {i}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment