
Simple script to replace spaces w/dots for movies category?
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Simple script to replace spaces w/dots for movies category?
I am just looking for a script that will rename the folders of all completed downloads in the "movies" category, replacing any spaces in the folder name with dots. Appreciate if someone could help with this, thanks 

-
- Full Member
- Posts: 127
- Joined: June 27th, 2012, 9:55 am
Re: Simple script to replace spaces w/dots for movies catego
You can try this script if you'd like.
FYI, I just have it renaming the folder - it doesn't touch the files. If you'd like this changed, let me know.
FYI, I just have it renaming the folder - it doesn't touch the files. If you'd like this changed, let me know.
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Thanks for your help! However, I'm on linux 

-
- Full Member
- Posts: 127
- Joined: June 27th, 2012, 9:55 am
Re: Simple script to replace spaces w/dots for movies catego
Oh, okay. That should be relatively simple, too. I'll see if I can knock something out when I'm near a computer again.
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Thanks so much chief! I'm so terrible with scripting, your help is greatly appreciated 

Re: Simple script to replace spaces w/dots for movies catego
A python script you can run to replace spaces in directory names with dots.
Developed and tested on Linux.
Developed and tested on Linux.
Code: Select all
import os
for path, dirnames, filenames in os.walk('.'):
for dirname in dirnames:
if dirname.find(' ') > -1 :
# Yes, a space in the directory name, so replace it:
newname = dirname.replace(' ','.')
print "Rename" , dirname, " ", newname
os.rename(dirname, newname)
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Thanks! So I have my scripts in /usr/share/sabnzbd/scripts, do I just make a file like spacestodots.py, and paste that in there? Then have that script run on movies?
Re: Simple script to replace spaces w/dots for movies catego
Just run it from the command line. Change the '.' to the correct directory.
If that works, you can procreed to call it from SABnzbd
If that works, you can procreed to call it from SABnzbd
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Okay, I have the script like this at the moment:
I run it from command line and get this:
If I run it with python2 or python2.x, there's no errors but it also doesn't do anything (movie directory remains as is with spaces).
Code: Select all
> cat spacestodots.py
import os
for path, dirnames, filenames in os.walk('/media/stuff/movies/Get\ the\ Gringo\ 720p\ BluRay\ x264\ DTS\ HDChina'):
for dirname in dirnames:
if dirname.find(' ') > -1 :
# Yes, a space in the directory name, so replace it:
newname = dirname.replace(' ','.')
print "Rename" , dirname, " ", newname
os.rename(dirname, newname)
Code: Select all
> python3 spacestodots.py
File "spacestodots.py", line 8
print "Rename" , dirname, " ", newname
^
SyntaxError: invalid syntax
Re: Simple script to replace spaces w/dots for movies catego
Well, it's for python 2, not for python 3.
Change the directory to work on to '/media/stuff/', not including the movie name.
Change the directory to work on to '/media/stuff/', not including the movie name.
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Okay I moved one movie into another folder to test the script with. The movie folder is inside /media/stuff/burning/, which is what I changed the path to in the script.
This is what I got:
This is what I got:
Code: Select all
> python2 spacestodots.py
Rename Get the Gringo 720p BluRay x264 DTS HDChina Get.the.Gringo.720p.BluRay.x264.DTS.HDChina
Traceback (most recent call last):
File "spacestodots.py", line 9, in <module>
os.rename(dirname, newname)
OSError: [Errno 2] No such file or directory
Re: Simple script to replace spaces w/dots for movies catego
OK, bug. Change to:
That works for me
Code: Select all
import os
# workdir = '/home/sander/kul-rename'
workdir = '/home/sander/Downloads/even twee' #### CHANGE this line to your movie directory
for path, dirnames, filenames in os.walk(workdir):
print "path:", path
for dirname in dirnames:
if dirname.find(' ') > -1 :
# Yes, a space in the directory name, so replace it:
newname = dirname.replace(' ','.')
fulldirname = path + '/' + dirname
fullnewname = path + '/' + newname
print "Rename" , fulldirname, " ", fullnewname
os.rename(fulldirname, fullnewname)
-
- Newbie
- Posts: 10
- Joined: March 20th, 2012, 5:57 pm
Re: Simple script to replace spaces w/dots for movies catego
Code: Select all
> python2 spacestodots.py
path: /media/stuff/burning
Rename /media/stuff/burning/Get the Gringo 720p BluRay x264 DTS HDChina /media/stuff/burning/Get.the.Gringo.720p.BluRay.x264.DTS.HDChina
