I am new to python and i am trying to write a script that moves .txt files from different sub directories to one new folder.
import os
import shutil
source_directory = os.path.join('mysourcedirectory', 'source')
target_directory = os.path.join('destinationdirectory', 'target')
operation= 'copy'
for src_dir, dirs, files in os.walk(source_directory):
if file.endswith(".txt"):
shutil.copy(os.path.join(target_directory, file))
Would someone be able to tell me where I am going wrong and how I can modify this? I'd also like to be able to modify these files (remove header, rename files to consecutive numbers). Can this still be done in one script?