4 AnswersNew Answer
import re filename=re.sub(r"(-| )","",filename) if you want the full solution or something I think the code given below will be OK however use try...except to handle errors import re import os # path os.chdir("storage/sdcard0/org.qpython.qpy/files/dice") files=os.listdir() for filename in files: # extension # would be better if enclosed in a try ... except block if filename[-4:] == ".dwg": # changing file name filename2=re.sub(r"(-| )","",filename) if filename != filename2: os.rename(filename,filename2) print("Fixed:", filename)
for char in text: if char == " " or char == "-": char = "" That would be my best guess. Basically, check every character, and if it is a space or hyphen, then make it nothing.
well the first answer I gave is the piece you need the second part is how to implement it in a for loop
Thank you I will try these! will they both work in a loop?