DEV Community

Discussion on: I love writing scripts to solve small problems

Collapse
 
jmcp profile image
James McPherson

This is the sort of relatively simple use-case that I'd just use a shell kinda-one-liner for. Admittedly, I've done thousands of these over the years (ripping CDs to flac and renaming etc) but shell is what comes to me first for this.

Something along the lines of

$ LIST=`find * -name \*pdf`;
$ for f in $LIST; do \
    N=`echo $f|sed -e"s, ,,g;s,(,_;s,),,g"`; \
    mv "$f" $N; done

You'd need to match that up with your preferred directory hierarchy and nomenclature; my bias is against spaces and suchlike in filenames so I remove and replace with - and _ depending on what I wish to make clear.

The great thing, though, is that the problem space here is simple enough that there are several different ways to solve it, each of which allow us to use our favourite language. But - please! - don't try doing regex in C!