我知道这个问题已经得到解答,但是我的应用程序使用了解决方案,但是我面临的错误无法解决。将文件夹从文件夹复制到文件夹python
我有一个文本文件中的数字列表,表示应复制的图像编号。这份名单是与此类似
7348
7352
7357
7360
7380
7381
.
.
.
的图像与名字
IMG_7348.jpg
IMG_7349.jpg
.
.
.
从文本文件中使用的数字,我想只有那些影像复制到不同的文件夹。这是Python代码我为同一
import os
import shutil
src = input('Enter the source folder');
dest = input('Enter the destination folder');
src_files = os.listdir(src)
with open("image_numbers.txt") as f:
lines = [line.rstrip('\n') for line in open('image_numbers.txt')]
for line in lines:
numbers_str = line
#print(numbers_str)
temp2 = str('IMG_')+numbers_str+str('.jpg')
#print(temp2)
for name_im in src_files:
#print(name_im)
print(name_im == temp2)
if name_im == temp2:
src_files_filt = temp2
#print('stored')
#numbers_float = [float(x) for x in numbers_str]
#map(float,numbers_str) works too
for file_name in src_files_filt:
full_file_name = os.path.join(src, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, dest)
写道当我使用打印语句,我能看到改革后的图像名称,并从SRC的名字是相同的,但声明
print(name_im == temp2)
给我
false
我无法找出原因
你能帮我解决这个错误吗?作为python的初学者,如果错误是基本的,请和我一起裸照。
我编辑我的解释为问题1,我认为只是由于print语句的位置说明。 – qwertyuip9