Cool FTA
Cool FTA

Reputation: 1

Need Python Code to Copy SourceFile > DestinationFile using Variable FileName from a List

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()

Upvotes: 0

Views: 13

Answers (1)

John Gordon
John Gordon

Reputation: 33285

infile is a file object, but copyfile() requires file names.

If you want to copy the same source file every time, use the name:

shutil.copyfile ("NFO.nfo", file_nfo)

Upvotes: 1

Related Questions