import os
def file_mv(src,dst):
try:
if not os.path.exists(src):
print(src+'不存在')
return False
dst_root=dst.rsplit('/',1)[0]
if not os.path.exists(dst_root):
os.makedirs(dst_root)
os.rename(src,dst)
else:
if not os.path.exists(dst):
os.rename(src,dst)
else:
print(dst+'已存在')
pass
except Exception as e:
print(repr(e))
raise
if __name__ == '__main__':
src='001.txt'
dst='1/001.txt'
file_mv(src,dst)
Python移动文件
最新推荐文章于 2023-05-21 17:45:52 发布