Hi Leo
That is WONDERFUL thank you so much.
I don't know how long that took you but it would have been so much work for me that it would not have got off the ground for ages. Years maybe never. Now I can play with it, use it and learn in the process. Thank you very very much.
It broke when I copied it into a user defined command straight off.
The error pointed right at the start of the script so it looked like I had missed a bracket or something.
I could not find the error so I started a fresh "Hello World" kind of script and started adding your script in incremenatlly until the fault arose again. It didn't.
I also added DOpus.Output statements in so I could understand what you have done.
Late entry: Original fault turned out to be script type = VB. Doh!
But I did find something rather interesting.
The DOpus.Outputs below show the results of the assignment of the variable num whenever a regex match is hit. All is well until a parse is made of the file_008.
Then num is returned as 0 (instead of 8 as I was expecting)
Indeed if I have a filename_008 in the directory filename_007 is opened.
Same if I have a filename_009
The sample output below is generated when the folder having 3 files in it as follows:
2018-09-REGISTER_008.xlsm
2018-09-REGISTER_007.xlsm
2018-09-REGISTER_006.xlsm
As mentioned, with the 3 files above, as suggested by the DOpus.Output below file_007 is opened instead of file_008.
Could it be the regex expression?
That looks ok to me.
The operative part I think would be
\d+
Which should match 1 or more digits.
Any ideas?
Once again my sincere thanks...
Script fragment showing DOpus.Output statements:
while (!folderEnum.complete)
{
DOpus.Output("!!!!!!!!!!!!!!!!!!!!!!!!!!"); //<<<
var subItem = folderEnum.Next();
if (!subItem.is_dir)
{
var pathString = subItem.RealPath + "";
if (pathString.match(regex))
{
DOpus.Output("0050 pathString MATCH :" + pathString); //<<<
var num = parseInt(pathString.replace(regex, "$1"));
DOpus.Output("0051 num :" + num); //<<<
if (pathHighest == "" || num > numHighest)
{
pathHighest = pathString;
numHighest = num;
}
}
}
DOpus.Output("0100 pathHighest " + nnn + " :" + pathHighest); //<<<
DOpus.Output("\r\n"); //<<<
nnn = nnn + 1;
DOpus.Output("reo005");
Sample DOpus.Output:
!!!!!!!!!!!!!!!!!!!!!!!!!!
0050 pathString MATCH :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_006.xlsm
0051 num :6
0100 pathHighest 0 :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_006.xlsm
!!!!!!!!!!!!!!!!!!!!!!!!!!
0050 pathString MATCH :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_007.xlsm
0051 num :7
0100 pathHighest 1 :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_007.xlsm
!!!!!!!!!!!!!!!!!!!!!!!!!!
0050 pathString MATCH :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_008.xlsm
0051 num :0
0100 pathHighest 2 :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_007.xlsm
!!!!!!!!!!!!!!!!!!!!!!!!!!
0100 pathHighest 3 :D:\Docs\Trading\2018-19\Accounting\Trade Register\2018-09-REGISTER_007.xlsm
END