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
Asked
Active
Viewed 442 times
1 Answers
0
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}')

Feline
- 773
- 3
- 14
-
But this shared drive has credentials; username and password. If I write this code in the Jupiter notebook it will access it? – mai May 06 '21 at 18:48
-
1if you don't have permissions to rename the files, then there is no way to rename them. If you DO have permissions, then the answer depends on whether it's a folder mounted on the network or local folder. – Feline May 06 '21 at 18:53