Dear All,
I am struggling to write my first "useful" python script, which is a backup tool.
After hours and hours of trial and error, I finally got it to create two different lists.
The first list is that of the files to be copied:
['C:\\Folder\\Foo.txt', 'C:\\Folder\\Folder1\\Foo1.txt', 'C:\\Folder\\Folder1\\Folder2\\Foo2.txt', 'C:\\FolderB\\FooB.txt', 'C:\\FolderB\\FolderB1\\FooB2.txt']
The second one consists of combined absolute destination paths of such files (in the local folder of the script in a removable media)
target_paths = ['F:\\Programming\\backup_script\\Folder\\Foo.txt', 'F:\\Programming\\backup_script\\Folder\\Folder1\\Foo1.txt', 'F:\\Programming\\backup_script\\Folder\\Folder1\\Folder2\\Foo2.txt', 'F:\\Programming\\backup_script\\FolderB\\FooB.txt', 'F:\\Programming\\backup_script\\FolderB\\FolderB1\\FooB2.txt']
The issue is that, for instance, "shutil.copy(target_files[0], target_paths[0])" will only work if the destination folder already exists. The destination folder is not created automatically. I need the original folder structure, so saving all files in the current folder is not a solution.
shutil.copytree() won't solve my problem as well because I am not copying the whole source folder, but only some specific files (there is a selection according to the time stamps of the files).
Is there any simpler way to get around this other than a painful combination of "os.path.exists" and "os.mkdir"?
Many thanks in advance for any possible help.
Yeti
P.S. - For reference, I am attaching the script. I know the sytle is terrible (vomitable) and that I should use functions and etc., but this was supposed to be only a "proof of concept" version. The problem is specifically on line 78.