Count back n amount of filename revisions

Discuss and share scripts and script files...
Post Reply
hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Count back n amount of filename revisions

Post by hermhart »

I have tens of thousands of files that need to be sifted through and at times will need the last n amount of revisions for several different filenames. Is there a way to count backward from the latest revision of a file to get the latest or the latest and n amount of files from the latest?

File schemes look like below, and the revision is always after the tilde '~'. Extra problems are the revisions start as a dash '-' and work their way up the alphabet: -, a, b, c, -> aa, ab, ac, etc. But there could also be: -, a, b, b1, b2, c, d, -> aa, ab, ac, etc.

I can make the input selection for selecting the filenames that I need, along with the input for it to ask how many revisions back I want to go. I just can't figure out how to have it find the latest revision for the file(s) and count back the amount of revisions and select them.

File schemes:
filename001~-.txt
filename001~a.txt
filename001~b.txt
filename001~c.txt
filename001~c1.txt
filename001~d.txt
filename001~e.txt
filename001~e1.txt
filename001~e2.txt
filename001~f.txt
filename001~g.txt
|
filename001~aa.txt
filename001~ab.txt
filename001~ac.txt


filename002~c.txt
filename002~d.txt
filename002~e.txt
filename002~f.txt
filename002~g.txt
filename002~h.txt
filename002~i1.txt
filename002~j.txt
|
filename002~aa.txt
filename002~ab.txt
filename002~ac.txt

If anyone can figure that out, that would be amazing.

Thank you!

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Count back n amount of filename revisions

Post by highend »

formatlist() can sort file (names) naturally so that e.g. this randomized list (for demonstration purposes only but it would work even for manually sorted files in a list pane):

Code: Select all

R:\tst\filename001~d.txt
R:\tst\filename001~a.txt
R:\tst\filename001~ac.txt
R:\tst\filename001~ab.txt
R:\tst\filename001~aa.txt
R:\tst\filename001~b.txt
R:\tst\filename001~c.txt
R:\tst\filename001~c1.txt
R:\tst\filename001~e1.txt
R:\tst\filename001~e2.txt
R:\tst\filename001~e.txt
R:\tst\filename001~g.txt
R:\tst\filename001~f.txt
R:\tst\filename001~-.txt
would result in:

Code: Select all

R:\tst\filename001~-.txt
R:\tst\filename001~a.txt
R:\tst\filename001~aa.txt
R:\tst\filename001~ab.txt
R:\tst\filename001~ac.txt
R:\tst\filename001~b.txt
R:\tst\filename001~c.txt
R:\tst\filename001~c1.txt
R:\tst\filename001~d.txt
R:\tst\filename001~e.txt
R:\tst\filename001~e1.txt
R:\tst\filename001~e2.txt
R:\tst\filename001~f.txt
R:\tst\filename001~g.txt
and then you don't need anything else to do to get the number of revisions by using gettoken(), because
it can get items till the end with a start parameter, in this case the last 5 revisions

Code: Select all

$revisions = gettoken(<the files above>, -5, <crlf>, , 2);
selectitems does the selection afterwards (<crlf> would need to be replaced with "|")...
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Re: Count back n amount of filename revisions

Post by hermhart »

highend,

You take to me what seems to be so difficult and you make it so much more understandable and simplistic.

Thank you so much for making it easier than what I thought it was!

I have a great place to start now.

Thank you very much.

Post Reply