{"id":790,"date":"2016-12-02T18:03:12","date_gmt":"2016-12-02T23:03:12","guid":{"rendered":"https:\/\/www.devolve.net\/blog\/?p=790"},"modified":"2016-12-02T12:32:08","modified_gmt":"2016-12-02T17:32:08","slug":"rename-iconv","status":"publish","type":"post","link":"https:\/\/www.devolve.local\/rename-iconv\/","title":{"rendered":"Rename and Iconv are like Chocolate and Peanut Butter"},"content":{"rendered":"

The features of iconv<\/strong> are probably built into Perl rename<\/strong> (aka prename<\/strong>), but when I tried the example from the man page, it kept generating an error message. I presume this is due to a missing Perl module. Here’s the error:<\/p>\n

Use of uninitialized value $out_enc in concatenation (.) or string at \/%homebrew%\/bin\/rename line 149.\r\nNo such encoding<\/pre>\n

So I suppose if we don’t care much about speed then we can just use an external utility like iconv<\/strong> to help convert a whole bunch of crap file names to something a little more universally-digestible. Change to the directory with the unfriendly file names and then run this rename<\/strong> and iconv<\/strong> combo to bulk rename them:<\/p>\n

echo -n \"\/usr\/bin\/iconv -f utf-8 -t ascii\/\/TRANSLIT\" > ~\/bin\/2ascii\r\nchmod +x ~\/bin\/2ascii\r\nrename -P ~\/bin\/2ascii -Xz -e 's\/_(\\W)_\/$1\/g; s\/__+\/_\/g;' *<\/pre>\n

I just renamed over two thousand files with this so I haven’t looked at all of them, but so far it looks like it’s done a great job.<\/p>\n

rename 0.3 you can find here: http:\/\/www.perlmonks.org\/?node_id=303814<\/a>, but I got it from homebrew.<\/p>\n","protected":false},"excerpt":{"rendered":"

The features of iconv are probably built into Perl rename (aka prename), but when I tried the example from the man page, it kept generating an error message. I presume this is due to a missing Perl module. Here’s the error: Use of uninitialized value $out_enc in concatenation (.) or string at \/%homebrew%\/bin\/rename line 149. […]<\/p>\n","protected":false},"author":3,"featured_media":791,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[34],"_links":{"self":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/790"}],"collection":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/comments?post=790"}],"version-history":[{"count":4,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/790\/revisions"}],"predecessor-version":[{"id":795,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/790\/revisions\/795"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media\/791"}],"wp:attachment":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media?parent=790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/categories?post=790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/tags?post=790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}