我想创建一个代码来帮助我复制类似的jpg文件。所以知道这些文件是否存在对我来说很重要。在
为此,我写下了以下代码:
from os import path
import shutil
oldfile = input("Which file do you want to copy? write that in numbers : ")
fadress = input("What is your file adress : ")
newfadress = input("Where do you want to copy your file : ")
f_num2 = oldfile.split('-')
for each_num in f_num2:
print(each_num)
newname = '_DSC{}.JPG'.format(each_num)
new2 = 'DSC_{}.JPG'.format(each_num)
if path.isfile(fadress + '\\' + newname):
shutil.copy(fadress + '\\' + newname, newfadress)
print(newname)
elif path.isfile(fadress + '\\' + new2):
shutil.copy(fadress + '\\' + new2, newfadress)
print(new2)
它在国际单项体育联合会之前起作用了陈述。但是似乎if语句没有获取os.path.isfile文件功能。什么我该怎么做才能让这个代码生效?在
您能在使用
fadress
之前剥离它并使用path.join
连接路径吗?在(或)在读取
^{pr2}$fadress
本身时将其剥离?在相关问题 更多 >
编程相关推荐