Snippet 1 - Create copies of files

python code to create file copies

·

1 min read

When there is a need to create copies of certain files with different filename for any purpose below code block could be used

Example: I have a file scale_test_1_profile_b.yaml and I need to create scale_test_1_profile_m.yaml

On bulk if I need to create such copies of profile_b files to profile_m then below script can be used.

import os
import shutil 
arr = os.listdir('/Users/cloudqa/environment_files/')
print(arr)

for filename in arr:
 if 'profile_b' in filename:
   print filename
   print "generating profile m files"
   newfilename = filename.replace('profile_b', 'profile_m')
   print "generated " + newfilename
   shutil.copyfile(filename, newfilename)