Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Snake X on June 24, 2011, 01:31:19 pm

Title: (somewhat) simple program request
Post by: Snake X on June 24, 2011, 01:31:19 pm
I have a request for a somewhat simple program in python. I want a program that can replace _ in file names with a space (these files are all in 1 folder so i can run the program in the same folder if that helps). I have several files in a folder with _'s that should be spaces but there are soo many that a program would be much better. Thanks.
Title: Re: (somewhat) simple program request
Post by: Munchor on June 24, 2011, 01:46:10 pm
/me was challenged!

Code: [Select]
import os
import sys

for i in os.listdir(sys.path[0]):
    os.rename(i,i.replace("_", " "))

The script has to be placed in the folder. You run it and it changes all "_"'s in files to " "'s.

Also, even though the code sounds simple, it was not so simple :)
Title: Re: (somewhat) simple program request
Post by: Snake X on June 24, 2011, 02:00:24 pm
thanks so much, it worked :)
Title: Re: (somewhat) simple program request
Post by: Munchor on June 24, 2011, 02:14:25 pm
thanks so much, it worked :)

No problem, it's a pleasure :)