How to find a complete way to the folder, end up and copy the contents
-
So, in the folder on.
C:\Users\Server\AppData\Roaming\Spotify\Users
There's a lot of folders, but I need to know the name of all folders with the end--user, that's what they call me.eg9no0brqmzrmfy6crh7e7fsy-user
andrplc59ty0gmhfy4q8tgaz8gyt-user
I'm done.-user
I need to know the name of the folder, and copy her contents into another folder.
-
It's through one os library. Yeah, I know that os.system is not a very good tone, but piton work with folding is terrible. So it's better and clearer. The folder is here for Linux. Windows is a little different.
import os
BASE_DIR = '/Ваша папка/'
TARGET_DIR = '/Ваша папка назначения/'all_dirs = [x[1] for x in os.walk(BASE_DIR)][0]
user_dirs = list(filter(lambda x: x.endswith('-user'), all_dirs))
user_dirs = list((BASE_DIR + x) for x in user_dirs)Для Linux
for dir_ in user_dirs:
os.system(f'cp -r {dir_} {TARGET_DIR}')Для Windows
for dir_ in user_dirs:
os.system(f'xcopy {dir_} {TARGET_DIR}')