-1

A folder named Folder have several sub folder Sub Folder A, Sub Folder B and Sub Folder C

I want to make them sub folder a, sub folder b and sub folder c

Is there any way to that?

Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70
  • You could check this out if it helps? https://www.tutorialspoint.com/python/os_rename.htm – Henri May 12 '22 at 07:25
  • 3
    Why "*using pandas*"? Can you be more explicit (are you talking about actual folders or strings?), because now your question sounds a bit like "*How can I fry eggs using my bike?*" ;) – mozway May 12 '22 at 07:35

3 Answers3

1

Not sure there is a function in pandas to do that. However the method os.rename() should do the trick when used in combination with os.walk(directory):

Jose
  • 11
  • 1
1

I think you don't need pandas here, you can rename with os.rename(folder, newname).

import os

os.rename(folder, new_name)

You need the exact path to the folder, for example, 'Folder/FolderA'

Icenore
  • 96
  • 6
1

Alternatively you can use shutil.move(old_path, new_path).

import shutil

old_path = r"C:\Users\adj\Desktop\root_dir\Sub Folder A"
new_path = r"C:\Users\adj\Desktop\root_dir\sub folder a"

shutil.move(old_path, new_path)

But based on your example, maybe you just want to lower case the folders name? Then you can use os.rename() and the lower() method

import os

root_folder = r"C:\Users\adj\Desktop\root_dir"
for f in os.listdir(root_folder):
    f_path = os.path.join(root_folder, f)
    os.rename(f_path, f_path.lower())
alexdjulin
  • 79
  • 1
  • 4