Sunday, 6 February 2011

Directory Management with KRename

Yesterday, I got a very interesting e-mail from Todd about using KRename. His request required one new feature which was added to KRename SVN and makes KRename even more powerful. So, I think his usecase is interesting enough to be shown here.

First of all, he has several files which he wants to sort into different directories based on parts of their names. If the filename contains the word "essay" it is supposed to go into a subdirectory called "essay/" and the same should be done for the memo's. His example list of files looks like this:

Work Essay for fred.txtWork Essay for bob.odtWork Essay for alice.docWork Memo for mary.odtWork Memo for ben.txtWork Memo for carey.doc

At the end, we want a directory and file structure like this:Essay/Work Essay for fred.txtEssay/Work Essay for bob.odtEssay/Work Essay for alice.docMemo/Work Memo for mary.odtMemo/Work Memo for ben.txtMemo/Work Memo for carey.doc

You can create directories in KRename during renaming of files using the [dirsep] operator or by simply using a / (slash) in the template. So, the template newdir[dirsep]$ will create a new directory called newdir and move all files to this directory. The token $ is KRename' way of saying, "insert the original filename here".

Now, one can combine this feature with the powerful regular expressions. Just go to the "Search and Replace ..." dialog and enter the regular expression Work ([\w]+) for and replace it with \1[direp]Work \1 for. The backreference \1 inserts a matched string from the regular expression into the results. Thereby, we can include either "memo" or "essay" in the new directory name. The matched part is indicated by brackets in the regular expression.

To make this work, one new feature was added to KRename. The dialog contains a new checkbox which allows to enable processing of KRename tokens in the replacement string of find and replace. We need this feature to process the [dirsep] token correctly and create a new directorySee the screenshots below.

If you have similar interesting usecases for KRename or questions on how to do thinks, do not hesitate to write a mail to our mailinglist!

8 comments:

He told the Sunday Mirror: "I said a few years ago that I will be here until the end of my contract.mmtangkas But I would like to finish my career here. We are continuing talks."Everybody knows what I feel about Chelsea and what I want.ผลบอล "Villas-Boas says the situation is still up in the air, adding: "He knows our offer and he has made a counter offer.