Copy and rename files on shared drive

523 Views Asked by At

I've a folder on shared drive containing other folders each with name 'date of creation', each of them has an excel file I need to get the excel file in each folder and rename it with its folder name (date of creation) is there any way to do it . Can anyone help me please

1

There are 1 best solutions below

2
On
from glob import glob
from pathlib import Path

drive_path = 'my_drive_path'
folders = glob(f'{drive_path}/*')

for folder in folders:
    folder_name = Path(folder).name
    files = glob(f'{folder}/*')
    for file in files
        Path(file).rename(f'{Path(file).parent}/{folder_name}')