Auto commit

上级 df352508
print('欢迎来到 InsCode')
\ No newline at end of file
print('欢迎来到 InsCode')
# coding=gbk
import os
def rename_dir(root_dir):
for root, dirs, files in os.walk(root_dir, topdown=False):
for dir_name in dirs:
if "abc" in dir_name:
old_path = os.path.join(root, dir_name)
new_path = os.path.join(root, dir_name.replace("abc", ""))
os.rename(old_path, new_path)
for file_name in files:
if "abc" in file_name:
old_path1 = os.path.join(root, file_name)
new_path1 = os.path.join(root, file_name.replace("abc", ""))
os.rename(old_path1, new_path1)
print("ok2")
'''
import os
def rename_dir(path):
for root, dirs, files in os.walk(path, topdown=False):
for name in dirs:
if 'xxx' in name:
new_name = name.replace('xxx', 'yyy') # 'xxx'==>'yyy'
os.rename(os.path.join(root, name), os.path.join(root, new_name))
print('wanc')
'''
'''
# write changelog to file
f = open(os.path.join(os.path.expanduser('~'),"Desktop") + "\\changelog.txt", "w")
for i in range(len(full_path_filenames)):
if new_full_path_filenames[i] != full_path_filenames[i]:
new_path_filenames = new_full_path_filenames[i].replace(test_path,'D:\src')
path_filenames = full_path_filenames[i].replace(test_path,'D:\src')
f.write(path_filenames + "\n=>" + new_path_filenames + "\n\n")
f.close()
# write oversized names to file
f = open(os.path.join(os.path.expanduser('~'),"Desktop") + "\\oversize.txt", "w")
for i in range(len(new_full_path_filenames)):
if len(new_full_path_filenames[i].split("\\")[-1]) > 31:
f.write(new_full_path_filenames[i] + " -> " + str(len(new_full_path_filenames[i].split("\\")[-1])) + "\n")
f.close()
'''
root_dir = "E:\\1111"
rename_dir(root_dir)
'''
import os,random
path1="E:\\1111"
for paths, dirnames, filenames in os.walk(path1,topdown=False):
print("Current path:",paths)
print("Folder in the current path:",dirnames)
print("File name in the current path:",filenames)
print("\n")
for filename in filenames:
filename_path=os.path.join(paths,filename)
index = filenames.find("NOES_12")
filename = filenames[:index]
new_filename = filename
new_filename_path=os.path.join(paths,new_filename)
os.rename(filename_path,new_filename_path)
print(filename_path,"===>",new_filename_path)
for dirname in dirnames:
dirname_path=os.path.join(paths,dirname)
new_dirname=str(random.randint(100,999))
new_dirname_path=os.path.join(paths,new_dirname)
os.rename(dirname_path,new_dirname_path)
print(dirname_path,"===>",new_dirname_path)
print(result)
'''
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册