I am trying to achieve the following the following in python:
I need to be able to copy and entire subfolder contents to another folder. However, i am not able to define the source path as the name of the main folder would change.
Source: C:\user\Week1\day1\DesiredFolder
C:\user\Week1\day2\DesiredFolder
Destination: C:\user\Output\DesiredFolderContents
In this case i should be able to copy the desired folder contents to the destination folder.
I am a novice to python and any help would be most appreciated.
Thank you!
Please find my code below.Thank you for your help
import os
import shutil
fullpath = os.path.join
start_directory2 = "D:\\RECS GRAPHS\\GRAPHS WEEKLY\\WEEK 2\\"
desiredfolder2="D:\\RECS GRAPHS\\WEEKLY DATA\\WEEK 2\\DesiredFolder\\"
def main():
for dirname,dirnames, filenames in os.walk(start_directory2):
for filename in dirnames:
source = fullpath(dirname,filename)
if dirname.startswith("DesiredFolder_Name"):
shutil.copytree(source,desiredfolder2)
if __name__ == "__main__":
main()