def f_rename(url):
s1 = re.findall(r'(\d+\.\w*).*',url)
s2 = ''.join(s1)+'.ev4'
return s2
def get_file(u):
if os.path.isabs(u):
pass
if not os.path.isdir(u):
print('路径不存在或者是非文件夹',u)
return
for item in os.listdir(u):
item = os.path.join(u,item)
if os.path.isdir(item): # isdir 判断当前文件夹存在
get_file(item)
continue
if os.path.isfile(item): # isfile判断当前文件存在
url_dir, url_file = os.path.split(item) # 对文件进行解包 文件目录和文件名
url_file = os.path.join(u,url_file)
url_file1 = os.path.join(u,f_rename(url_file))
if url_file1 != url_file :
print(url_file, url_file1)
a_url = os.rename(url_file,url_file1)
continue
else:
continue
print(item,'辨别不出文件类型')
get_file('D:\python\done1')