需要Python代码使用List中的Variable FileName复制SourceFile> DestinationFile

问题描述 投票:0回答:1
import os
from shutil import copyfile

change to my working directory

os.chdir('Z:/')

confirm my current working directory

print (os.getcwd())

this is the file source I would like to copy

infile = open("NFO.nfo","r")

this reads into "file_nfo" all the "file names" with NFO extension that I am trying to copy using the "shutil.copy" to copy SourceFile > DestinationFile

for f in os.listdir ():
    file_name, file_ext = os.path.splitext(f)
    file_nfo = file_name+'.nfo'
    print (file_nfo)
    shutil.copyfile (infile, file_nfo)

copyfile (infile, outfile) - this is not working - any help is appreciated - I would like to thank you in advance for taking the time to read this.

this closes the SourceFile

infile.close()
python copying
1个回答
1
投票

infile是一个文件对象,但copyfile()需要文件名。

如果要每次都复制相同的源文件,请使用以下名称:

shutil.copyfile ("NFO.nfo", file_nfo)
© www.soinside.com 2019 - 2024. All rights reserved.