how to use wildcards in krename?

Asked by quixote

I'm using krename within krusader to recursively rename sets of image files. The gallery program I'm using wants thumbnails named "TN-filename.png". I have "filename.png"

I thought I could do the following in the multi-rename window:
Find: *.png Replace: TN-*.png

But * doesn't seem to mean anything to krename.

Is there an easy way to do this? Possibly using a shell script? I tried: [code]find . -type f -name '*.png' | while read PNG do for file in '*.png'; do mv "$file" "TN-$file"; done
[/code] but I get the error [code]bash: read: `*.png': not a valid identifier
[/code] and nothing I do seems to fix it. :(

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu krename Edit question
Assignee:
No assignee Edit question
Solved by:
Selene ToyKeeper
Solved:
Last query:
Last reply:
Revision history for this message
Best Selene ToyKeeper (toykeeper) said :
#1

Krename uses regular expressions instead of "glob" wildcards.

The biggest difference is that, in a glob pattern, "*" means "match anything", and "?" means "match one character". But in a regular expression, "*" mean "match 0 or more of the preceeding set" and "." means "match one character". So, the "*" you are used to should instead be ".*", and all normal "."s need a backslash before them.

To put part of the search result into the replacement, put parenthesis around it and then refer to it by number (from left to right).

So, to rename *.png to TN-*.png, the syntax would be...

  Find: (.*)\.png
  Replace: TN-\1.png

The syntax for more advance patterns may vary, because there are several regular expression engines and I'm not sure which one krename uses. But the example above worked when I tried it.

I find it easier to do this on the command line, using the "rename" utility. Its syntax is:

  rename 's/search/replace/;' file1 file2 file3...

With "rename", you could rename your images by running...

  rename -v 's/(.*)\.png/TN-$1.png/;' *

Or, more simply, to just insert a prefix for all PNG files...

  rename -v 's/^/TN-/;' *.png

I recommend running it with "-n" (dry run) instead of "-v" first, to see what it would do.
The regex syntax for "rename" is here:

  http://perldoc.perl.org/perlre.html

For another example, I've found I can rename anime with something like..

  rename -v 's/\[(.*)\]_(.*)_-_(\d\dv?\d?)_\[(........)\]/$2.$3.$1.$4/;' *.avi

This would convert ...

  before: [Group]_Title_-_25_[DE2921C7].avi
  after: Title.25.Group.DE2921C7.avi

If you often need to rename things with similar patterns, just save your rename commands to a script. Writing the regular expressions may be a little confusing at first, but it saves time later.

Revision history for this message
quixote (commer-greenglim) said :
#2

Scott, that's *beautiful* and exactly what I needed. I looked in my big fat linux book, and didn't see that distinction between glob and regex use of *. And I tried several times to google for something like that excellent perl link -- which is what I've been looking for for months! -- and never found it.

Thanks a million! You not only solved my immediate problem, you solved several others at the same time.

Revision history for this message
quixote (commer-greenglim) said :
#3

Thanks Scott Scriven, that solved my question.

Revision history for this message
L-Bit (albertfromnz) said :
#4

However, if you preferred to use KRename,
replacing $ with * commands the file to be renamed Uppercase First Letter.png
If you want to convert filename.png to TN-filename.png
Place TN- before the $ sign and then process.... done.