-2

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

mai
  • 1
  • 1
  • R: `file.rename(fm,to)`. Python: `os.rename(fm,to)`. PowerBI/knime: no idea, though since PowerBI allows you to run R and Python scripts, that should be a direct application. No clue about [tag:knime]. – r2evans May 06 '21 at 18:18

1 Answers1

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
  • 1
    if 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