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.txt
Work Essay for bob.odt
Work Essay for alice.doc
Work Memo for mary.odt
Work Memo for ben.txt
Work Memo for carey.doc


At the end, we want a directory and file structure like this:

Essay/Work Essay for fred.txt
Essay/Work Essay for bob.odt
Essay/Work Essay for alice.doc
Memo/Work Memo for mary.odt
Memo/Work Memo for ben.txt
Memo/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 directory
See 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:

My Family said...

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.

anhkuzit said...

What kind of man
Would leave you standing in the cold
Must’ve been a silly one
To sacrifice a pot of gold
You’re the kind of woman
That needs a man that’s always there
Kirk Sanford Sightline Paymentsbetting guide

obama said...

Girl I’ll be around, never let you down
For all that it’s worth
I give good love (good love, good love, good love, good love)
I give good love (good love, good love, good love, good love)

Online Bingovalutahandel

kosovohp said...

I give good love
I'll buy your clothes
I'll cook your dinner too
Soon as I get home from work
I'll pay your rent
Your faithful lover
winning lottery numbersspy gadget

kosovohp said...

socks5 | socks proxy | proxy free | proxy
socks proxy | socks5 | proxy | proxy free

cuongthao said...

What kind of man
Would leave you standing in the cold
Must’ve been a silly one
dkm anhkuzit dm may`

uknowme said...

Girl I’ll be around, never let you down
For all that it’s worth
I give good love (good love, good love, good love, good love)
I give good love (good love, good love, good love, good love)
serengeti safari

what to do in

uknowme said...

I give good love
I'll buy your clothes
I'll cook your dinner too
Soon as I get home from work
I'll pay your rent
Your faithful lover
Toronto Limo Bus

manufacturing erp software