I would like to be a be able to select some files and click a button which would rename all the selected files. EACH file should be given a truncated version of its current name. I want to keep the first (assume) 9 characters of its current name (plus the current extension).
if one of the files is named: thisisatest.txt prior to the rename, after the rename its name would be: thisisate.txt
I am not sure if Dopus commands can do this. It could be doable using VBScript via the LEFT function.
Thank you, the RegEx is definitely a good way to go. Unfortunately I did not realize that part of the string I want to keep is a date and the number of characters can vary depending on which month/day it is. I think I can search for the underline character "_" in the name (which follows the date) and then take it and the following 3 characters plus the date and make those the characters to keep (plus the extension). I will play with it.
This is what I came up with based on the example above:
Rename PATTERN "(^.)_(.{3})(.).(.*)" TO "\1_\2.\4" REGEXP
It is intended to take all the characters before the underscore, the underscore, and the 3 characters after the underscore plus the extension. I did some quick tests and it seems to work. I will have to wait till I download the "real" files on Saturday to be sure.
Again I would not have been able to do this without the examples above. Thanks for the help.
Well, its Saturday and I downloaded the "real" files AND, there was a glitch. As it happens there was another underscore in the file name and the \2 picked the second one as well - and the three characters after it. I solved the issue by putting another underscore after that logic:
Rename PATTERN "(^.)(.{3})(.).(.*)" TO "\1_\2.\4" REGEXP
But that just happens to work with these file names. Is there a way to grab the FIRST occurrence of the underscore and the three following characters and ignore any other underscores in the name?
Sounds you need to make your regex non-greedy, lookup the "?" operator for this and apply it the appropriate group/character.
RegExes are greedy by default, so something like (.*_) will always get you anything before the last underscore found, the "?" helps here to limit the match to the first occurrence of the underscore.
I tried the ? as suggested by tbone, but could not get that to work for me. I might have been missing some needed grouping.
using Leo's suggestion I was able to get the command to work as intended with the string below.
Rename PATTERN "(^[^]*)(.{3})(.).(.)" TO "\1_\2.\4" REGEXP
Thanks to both of your for your response.
I do not understand why the previous logic seemed to grab the LAST underscore and then the three characters following IT. I would interpret that PREVIOUS logic as: grab characters until you find an underscore (/1), grab the next three characters(/2), grab characters until you find a period (/3), then grab all the rest of the characters (/4). Why did using the NOT underscore in the first group make such a difference?
Your interpretation is wrong. Regexps are "greedy" by default and .* will grab the most characters it can while still matching the string. (This is usually a good thing, but not always.)