Map regex replace on folders only
Posted: 27 Jul 2017, 23:15
What would be the best way to replace a series of strings in folder names with others but otherwise leave the file untouched?
I was thinking of a csv file with a map of replacements, for example:
And such but I'm struggling to find the correct mix of logic and bindings to make this work.
The above however [should] work on single files and not on the folder while the objective would be to have:
An added bonus would be if I could also move said folder to another location and leave a symlink to it in its place with the original name.
I was thinking of a csv file with a map of replacements, for example:
Code: Select all
[rarbg];
[ettv];ETTV
...
Code: Select all
import java.util.regex.Pattern
def map = csv('path/to/file.csv')
def s = String
map.each{ k, v ->
def p = Pattern.compile(Pattern.quote(k), Pattern.CASE_INSENSITIVE)
s = file.getPath().replaceAll(p, v)
}
return s
Code: Select all
Big.Hero.6.2014.1080p.BluRay.x264-SPARKS[rarbg]/ -> Big.Hero.6.2014.1080p.BluRay.x264-SPARKS/