os.path.isfile文件不与国际单项体育联合会的政治家合作

2024-05-23 16:24:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个代码来帮助我复制类似的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文件功能。什么我该怎么做才能让这个代码生效?在


Tags: 文件path代码inputnumfileeachprint
1条回答
网友
1楼 · 发布于 2024-05-23 16:24:19

您能在使用fadress之前剥离它并使用path.join连接路径吗?在

path.isfile(path.join(fadress.strip(), newname))

(或)在读取fadress本身时将其剥离?在

^{pr2}$

相关问题 更多 >