Removing punctuation from file names

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
ukoda
Posts: 5
Joined: 18 Oct 2014, 21:19

Removing punctuation from file names

Post by ukoda »

I like clean file names, just characters aplha-numnerics, period and underscore i.e. A-Z, a-z, 0-9, ., and _. I make an exception for spaces so Kodi scrapers will work. Currently my script uses this line:

Code: Select all

def episodeFormat = '''/mnt/dst/TV/{n.ascii().replace(':', '')} ({y})/Season{s}/{n.ascii().upperInitial().space('.').replace(':', '')}.{s00e00}.{t.ascii().space('_').replace(':', '')}'''
Looking at the documentation I'm guessing there is no simple function to do this so I will need multiple replace function? If I use the replace function I'm not sure how to specify apostrophes, ampersands, slash and backslashes, ', &, / and \. How do other people keep their file names clean?

I am running version 4.5 on a CentOS server.
User avatar
rednoah
The Source
Posts: 23947
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Removing punctuation from file names

Post by rednoah »

The ascii() function should be fine if you don't want unicode characters in your filesystem.

As for replace, there's regex:

Code: Select all

{'#test 1'.replaceAll(/\W/, ' ')}
@see http://docs.oracle.com/javase/8/docs/ap ... ttern.html
:idea: Please read the FAQ and How to Request Help.
Post Reply