Anyone know python?
Go to solution
Solved by WereCatf,
Well, looks like I'm getting no reply, so I'm just leaving this here:
#!/usr/bin/python3 from os import listdir, rename, chdir from os.path import isfile, join #Replace the path with whatever you like #Or write the code to get it from the command-line dirPath = "." chdir(dirPath) #Find only files, not directories listFiles = [f for f in listdir(dirPath) if isfile(join(dirPath, f))] for filename in listFiles: countHashes = filename.count("#") if(countHashes < 2): continue #Remove the 2nd .replace() here, if you just want to ignore the hash #Or change the space to whatever you want to replace the last hash into newFilename = filename.replace("#", "_", countHashes - 1).replace("#", " ") if(newFilename != filename): #Remove the 2nd .replace() here, if you just want to ignore the hash #Or change the space to whatever you want to replace the last hash into print("Rename {:s} to {:s}".format(filename, filename.replace("#", "_", countHashes - 1).replace("#", " ") )) if(isfile(newFilename) == False): rename(filename, newFilename) else: print("File already exists, not renaming.")

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now