import os
path_name = r'E:\BreakHis_dataset\validation\new' #原图片所在路径
save_path = r'E:\BreakHis_dataset\validation\malignant' #要保存的路径
i = 0
for item in os.listdir(path=path_name):
new_item = str(i)+'.jpg' #要保存的文件名
os.rename(os.path.join(path_name,item), os.path.join(save_path,new_item))
new_out = os.path.join(path_name, new_item)
print(new_out)
i+=1
os.rename("old_name","new_name")
import os,sys
print("当前目录:%s"%os.getcwd())
print("目录为:%s"%os.listdir(os.getcwd()))
#修改old.txt为new.txt
os.rename("old.txt","new.txt")
os.path.join() 起到拼接路径的作用
import os
Path1 = 'home'
Path2 = 'develop'
Path3 = 'code'
Path10 = Path1 + Path2 + Path3
Path20 = os.path.join(Path1,Path2,Path3)
print ('Path10 = ',Path10)
print ('Path20 = ',Path20)
输出
Path10 = homedevelopcode
Path20 = home\develop\code