yikesthisisamess
yikesthisisamess

Reputation: 83

Save a text file to multiple places via a list of file paths in a numpy array

I have a text file and I want to write it to a list of file paths I have saved in a numpy array. The code looks similar to this:

import numpy as np

img_file_path = ['/home/myname/testfolder/folder1', '/home/myname/testfolder/folder2', '/home/myname/testfolder/folder3'] #list of file paths
img_file_path = np.array(img_file_path) 
img_file_path.astype(str) #numpy array of file paths

constraints = open('/home/myname/Constrain.single')

My list of folder paths is much longer but I would like to save the file Constraints.single to each folder in my list of file paths. Is there any way to do this so I don't have to go through and paster the folder in manually?

Upvotes: 0

Views: 72

Answers (1)

Dan
Dan

Reputation: 1587

import shutil

img_file_path = ['/home/myname/testfolder/folder1', '/home/myname/testfolder/folder2',
                 '/home/myname/testfolder/folder3']
src = '/home/myname/Constrain.single'

for path in img_file_path:
    shutil.copy(src, path)

Upvotes: 1

Related Questions