我正在尝试重命名文件夹,
这就是我所拥有的,
for item in all_folders:
root_path = '/media/username/da5df9e4-cdc6-4d55-91e8-b2383e89165f/lion/'
new_root_path = root_path+item
for folders in os.listdir(root_path+item):
for index,value in enumerate(all_combined):
if folders.startswith(all_combined[index]):
os.rename(os.path.join(new_root_path,folders),os.path.join(new_root_path,'New'))
当我运行时,我得到:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-320-a1b27e11ba34> in <module>()
4 for index,value in enumerate(all_combined):
5 if folders.startswith(all_combined[index]):
----> 6 os.rename(os.path.join(new_root_path,folders),os.path.join(new_root_path,'New'))
OSError: [Errno 39] Directory not empty: '/media/username/da5df9e4-cdc6-4d55-91e8-b2383e89165f/lion/Tpct046/5mm portal' -> '/media/username/da5df9e4-cdc6-4d55-91e8-b2383e89165f/lion/Tpct046/New'
all_folders列表如下所示:
['t0118',
't046',
't042',
't003',
't024',
't016',
't011',
't065',]
all_combined列表如下所示:
all_combined = ['Thin Venous Phase',
'VENOUS THIN',
'Tripple Phase',
'Thin Venous Phase',
'Thin Venous Phase',
'Thin Venous Phase',
'5MM VEN0US',
'ARTERIAL THIN_0081',
'ARTERIAL THIN_0100',.........]
任何有用的建议都会有用,提前谢谢。
答案 0 :(得分:1)
尝试:
&#xA;&#xA; for all_folders中的项目:&#xA; root_path ='/ media / username / da5df9e4-cdc6-4d55-91e8-b2383e89165f / lion /'&#xA; new_root_path = os.path.join(root_path,item)&#xA;对于os.listdir中的文件夹(os.path.join(root_path,item)):&#xA; for index,enumerate中的值(all_combined):&#xA;如果folders.startswith(all_combined [index]):&#xA; os.rename(os.path.join(new_root_path,文件夹),os.path.join(new_root_path,文件夹+ '新'))&#XA; 代码>
&#XA;