我正在尝试将所有符合条件的图像复制到单独的文件夹中。我在通过熊猫读取的csv文件中有图像路径存储。当我尝试复制文件时,python附带文件不存在错误而文件确实存在。(我已经检查过)。我以前做过类似的事情,并且过去也能奏效。
下面是我正在使用的代码段
import os
import os.path
from dbfread import DBF
import pandas as pd
from pandas import DataFrame
import shutil
import errno
dTIMS = pd.read_csv('F:/Kwinana_Kerb/dTIMS.csv')
image = pd.read_csv('F:/Kwinana_Kerb/Image_dTIMS.csv')
#print dTIMS.columns
dTIMS_2109 = dTIMS.loc[dTIMS['Year'] == 2019]
#print dTIMS_2109
for index,row in dTIMS_2109.iterrows():
# dst = 'F:/Kwinana_Kerb/2019/'+str(int(row['Road']))+'_'+str(int(row['From_Add']))
dst = 'F:/Kwinana_Kerb/2019/'
print str(int(row['Road']))+'_'+str(row['From_Add']/1000)+'_'+str(row['To_Add']/1000)
image1 = image.loc[(image['ROAD_ID'] == row['Road']) & ((image['Sub Chainage (km)'] > row['From_Add']/1000)&(image['Sub Chainage (km)'] < row['To_Add']/1000))]
if image1.shape[0] >0:
print '-----------' + str(image1.shape[0])
for image_index,image_row in image1.iterrows():
src = os.path.join(str(image1.loc[image_index,'Image_Path']))
print src
print os.path.isfile(src)
# if os.path.isfile(src)
# try:
# shutil.copy(src,dst)
# except IOError as e:
# # ENOENT(2): file does not exist, raised also on missing dest parent dir
# if e.errno != errno.ENOENT:
# raise
# # try creating parent directories
## os.makedirs(os.path.dirname(dst))
## shutil.copy(src, dst)
输出如下所示。
106122_1.08_1.11
695_0.0_0.05
-----------5
F:/Kwinana_Kerb/Images/20180822_1538\Front Center \20180822_1538 Front Center 0001157.jpg
False
F:/Kwinana_Kerb/Images/20180822_1538\Front Center \20180822_1538 Front Center 0001158.jpg
False
F:/Kwinana_Kerb/Images/20180822_1538\Front Center \20180822_1538 Front Center 0001159.jpg
False
F:/Kwinana_Kerb/Images/20180822_1538\Front Center \20180822_1538 Front Center 0001160.jpg
False
F:/Kwinana_Kerb/Images/20180822_1538\Front Center \20180822_1538 Front Center 0001161.jpg
False
任何帮助将不胜感激。