Python Forum
Rename Multiple files in directory to remove special characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rename Multiple files in directory to remove special characters
#1
The purpose of the script below is to rename multiple folders in a directory. File is named 2324[folder 1], 3242343[Folder 2), 4343[folder 3]. The purpose of script is to rename files to keep only folder 1, folder 2, and folder 3 name. I currently have 20,000 folders to rename

#!/usr/bin/python
import os

path = r"/Users/princessnaana/Desktop/Python_Examples/Naana"

directory_list = os.listdir(path)

for f in directory_list:
    src = f
    dst = f[f.find('[') + 1:].replace(']','')
    replace_name = dst
    os.rename (dst)

when I print the script the code renames the files as intended however when I run the code it does not change the names of the folder in the directory.
buran write Feb-16-2021, 06:01 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Rename Multiple files in directory to remove special characters - by nyawadasi - Feb-16-2021, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through all files in a directory? Winfried 9 197 5 hours ago
Last Post: DeaD_EyE
  Copy xml content from webpage and save to locally without special characters Nik1811 14 913 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 456 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  python convert multiple files to multiple lists MCL169 6 1,545 Nov-25-2023, 05:31 AM
Last Post: Iqratech
Question Special Characters read-write Prisonfeed 1 620 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Rename files in a folder named using windows explorer hitoxman 3 740 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  change directory of save of python files akbarza 3 881 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  splitting file into multiple files by searching for string AlphaInc 2 897 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Rename all files in a folder hitoxman 9 1,488 Jun-30-2023, 12:19 AM
Last Post: Pedroski55
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,340 Jun-27-2023, 01:17 PM
Last Post: diver999

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020