|
Hi,
I have file lectures and I would like to change the nameing convention.
Currently, it has the format of {detail -} subject - author.wmv
I would like to rename with the nameing convention of author - subject { - detail}.wmv
Some observation, initialy, the author is at the end of the file name preceded by a seperator of minus sign.
{detail -} is optional and thus some file name utilize. Thus, we can have more than one minus sign as seperator but author name is always at end of file name preceded by the minus sign seperator.
Example file names;
e4 e5 - The Four Kn1ghts for Black - Vig0rito.wmv
e4 e5 The Sc0tch for Black - Part 1 - Vig0rito.wmv
2+1=2; A Practical Endgam3 Example from L1nares - P@schall.wmv
Result ( I would like. That is, lecturer seperator topic )
Vig0rito - e4 e5 - The Four Kn1ghts for Black.wmv
Vig0rito - e4 e5 The Sc0tch for Black - Part 1.wmv
P@schall - 2+1=2; A Practical Endgam3 Example from L1nares.wmv
Purpose, I would like to access material by author.
Thank in advance for your help.
|
|
|
|
|
You can use System.IO.Path.GetFileNameWithoutExtension() . Then find the position of the last "-" with the LastIndexOf('-') function of the string class. Build up your new string from the respective Substring() s.
|
|
|
|
|
Thank you for your reply Bernhard and introduction to system io.
Currently, I am using a free file renaming tool that utilize regexp. After looking at the coding and re-familiarizing myself with regexp and having no luck, I made a post. The next morning, I came with a quasi-solution. I do not want to spam the tool but it is the most complex rfr*k according to review.
What unique about this file title renaming is the number of seperators can vary. Thus, mp3 titles with challenging non-fix number of seperators would find this thread informative. I am stump trying to access the last seperator with $ anchor to create an expression and thus sent this sos.
Here is my quasi-solution and hope it helps some with similar problem.
(?x)(.*?)[ ]*?[-]+[ ]*?(.*) [ ]*?[-]+[ ]*?(.*) # start of swap 2 fields \3 zzzz \2 zzzz \1
(?x)[ ]*[-][ ] # Handle Linaries example _
(?x)(.*?)[ ]*?[_]+[ ]*?(.*)$ # Linaries example \2 zzzz \1
\bzzzz\b # Convert back to minus sign -
(.?)\bwmv\b # remove the .wmv after the author name to null
I use zzzz and _ as temporary strings with the understanding that they are unique in my files. Adapt accordingly. I adapted from a swap 2 fields expression. The five lines and replace work for my demo example. Thanks.
Edit: Some minor quirks but liveable. tx
modified 6-Aug-12 23:05pm.
|
|
|
|
|
OK, that's different background.
In that case, I'd rely on the "greedy" character of wild cards.
(?<part1>.*)\s-\s(?<part2>.*)(?<ext>\.wmv) will catch the parts and the extension,
and the re-order it to become part2 - part1.ext
|
|
|
|