I'm trying to create a sequence of folders which contains sub-folders which contains files with python.
The name of these folders come from a text file which has a list with the paths inside, like this:
songs\101_TNTOGCD\101_2020_CONTENT_LOOP_TNTOGCD.mov
songs\101_TNTOGCD\101_TNTOGCD_CONTENT_TC_A+B_CBLDESIGN2.mov
The number of the sub-folders it's not always the same, sometimes it can be two sub-folders and file, sometimes just one folder and file.
All of this must be created in a specified folder of my choice.
This is what I did so far:
import os
import shutil
import os.path
with open("C:\\Users\\Desktop\\folder1\\folder2\\folder3\\textfile.txt", "r") as g:
lines = g.readlines()
base_path = "C:\\Users\\Desktop\\folder1\\folder2\\folder3"
mov_origin = "C:\\Users\\Desktop\\folder1\\folder2\\folder3\\folder4\\file_000.mov"
for line in lines:
target = base_path
path = line.split("\\")
for i in range(len(path) - 1):
target += path[i]
if not os.path.exists(target):
os.makedirs(target)
else:
pass
target += "\\"
target += path[-1].replace("\n", "")
print(target)
shutil.copyfile(mov_origin, target)
But basically, when I run it, nothing happens. I didn't get any error, but nothing is created. What I'm doing wrong?
Thanks in advance for all your help!
UPDATE: The code was not working because of my mistake in the Run/Debug configuration in PyCharm. The wrong Script Path was selected.