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
#4
Try this and tell me if it prints out the files that you want to change and the names that you want to change them to.

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

directory_list = os.listdir(path)

for f in directory_list:
	if '[' in f and ']' in f :
		dst = f[f.find('[') + 1:].replace(']','')
		print (f, dst)
Reply


Messages In This Thread
RE: Rename Multiple files in directory to remove special characters - by BashBedlam - Feb-16-2021, 08:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Special characters in XML ForeverNoob 3 1,878 Dec-04-2024, 01:26 PM
Last Post: ForeverNoob
  deleting files in program files directory RRADC 6 3,360 Aug-21-2024, 06:11 PM
Last Post: snippsat
  Trying to generating multiple json files using python script dzgn989 4 2,484 May-10-2024, 03:09 PM
Last Post: deanhystad
  Filer and sort files by modification time in a directory tester_V 5 2,571 May-02-2024, 05:39 PM
Last Post: tester_V
  Loop through all files in a directory? Winfried 10 4,803 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  Copy xml content from webpage and save to locally without special characters Nik1811 14 5,395 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 1,421 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  python convert multiple files to multiple lists MCL169 6 3,394 Nov-25-2023, 05:31 AM
Last Post: Iqratech
Question Special Characters read-write Prisonfeed 1 1,504 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Rename files in a folder named using windows explorer hitoxman 3 2,006 Aug-02-2023, 04:08 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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