Page 1 of 1

Removing punctuation from file names

Posted: 18 Oct 2014, 22:14
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.

Re: Removing punctuation from file names

Posted: 19 Oct 2014, 00:12
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