我有一个包含很多图像的文件。每个图像的名称如下:
100304.jpg
100305.jpg
100306.jpg
ETC...
我还有一个电子表格,每张图片是一行,行中的第一个值是名称,名称后面的值是各种小数和0来描述每张图像的特征。
问题是,当我从工作表中提取名称时,会添加一个小数,这会导致文件无法通过 shutil.move()
import xlrd
import shutil
dataLocation = "C:/Users/User/Documents/Python/Project/sort_solutions_rev1.xlsx"
imageLocBase = "C:/Users/User/Documents/Python/Project/unsorted"
print("Specify which folder to put images in. Type the number only.")
print("1")
print("2")
print("3")
int(typeOfSet) = input("")
#Sorting for folder 1
if int(typeOfSet) == 1:
#Identifying what to move
name = str(sheet.cell(int(nameRow), 0).value)
sortDataStorage = (sheet.cell(int(nameRow), 8).value) #float
sortDataStorageNoFloat = str(sortDataStorage) #non-float
print("Proccessing: " + name)
print(name + " has a correlation of " + (sortDataStorageNoFloat))
#sorting for this folder utilizes the information in column 8)
if sortDataStorage >= sortAc:
print("test success")
folderPath = "C:/Users/User/Documents/Python/Project/Image Folder/Folder1"
shutil.move(imageLocBase + "/" + name, folderPath)
print(name + " has been sorted.")
else:
print(name + " does not meet correlation requirement. Moving to next image.")
我遇到的问题是 shutil.move(imageLocBase + "/" +name, folderPath) 出于某种原因,我的代码从电子表格中获取名称(例如:100304),然后添加一个“.0”所以当尝试要移动文件,它试图移动 100304.0(不存在)而不是 100304。
千巷猫影
绝地无双
qq_花开花谢_0
神不在的星期二
相关分类