This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have versions of compiled classes ina directory in this way:
I'd like to make a class to purge old versions. I've worked with files and RegExp, but I'm not sure how to start this taks. In some way I have to make an ordered list of this and then locate the old ones, bout I'm lost.
On way to approach this is to figure out the latest file from the time stamp. All the other ones are the oldest. Of course the compiler can possibly create multiple class files for the same source file. So you will have to figure somehow keep a track of it and work around that problem.
Just a shot in the dark, but depending on where your classes are coming from, you might want to consider using a version control tool like subversion.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I thought sure I posted a response to this but I don't see it.
At a quick read, your algorithm keeps the first name it comes across and deletes the rest. Is that keeping the oldest and deleting the newest or did I read it wrong?
If I got it right, the simple fix is to sort backwards. Change your comparator from name1.compareTo(name2) to name2.compareTo(name1). And I think your comparator can just compare the whole name without parsing off the version number, unless you're worried about comparing name_10 to name_2 which would come out wrong. But if the version is always three digits you can just compare full names.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Aug 31, 2007
Yes, I need the custom comparator because of the number of the digits referring the version. Can be foo_9.class and next foo_10.class
I didn't see that at the fist look (I thought it was always two), but is not fixed. It's only sure that the number is between "_" and ".class"
The algorithm keeps the first name because I need 1-n loop, but also can be 0 (which is not probable), so I need 1 + 0-n. But I'm keeping the last. note
where anterior is the first in the first loop (-: and in the next loops
anterior -> previous actual -> current
so I delete all but the las one of the matching name-without-number. May be with time stamp would be easier.
And referring to use svn, I don't have the knowledge, I'm afraid. Also its strange, because this automatic classes generated by a middleware software, are transfered to the test/production system ("standard" procedure), so I'm not really sure how a version control system can fit there... I'll have a look anyway, thanks about that.