From: d on
At the start of a run, I have an output directory called "answers"
which is from my last run. Before my new run, I want to move this to
"answers_1" and create a new answers dir. Then on a later run I will
have a new "answers" which I will want t o rename to "answers_2".

So each run, I want to look to see what the biggest # is in answers_#
and move the current answers to answers_(#+1).

I can glob the dirs and look through the #s, but I was wondering if
there is some easy or built-in way to do this in tcl.
From: Jeff Godfrey on
On 6/15/2010 2:33 PM, d wrote:
> At the start of a run, I have an output directory called "answers"
> which is from my last run. Before my new run, I want to move this to
> "answers_1" and create a new answers dir. Then on a later run I will
> have a new "answers" which I will want t o rename to "answers_2".
>
> So each run, I want to look to see what the biggest # is in answers_#
> and move the current answers to answers_(#+1).
>
> I can glob the dirs and look through the #s, but I was wondering if
> there is some easy or built-in way to do this in tcl.

There's really no "built-in" way of doing this (AFAIK), but it sounds
trivial. I'd probably write a routine that returns the next valid dir
number which works like this:

- glob for all existing dirs (answers_*).
- [sort -dictionary] the return list
- grab the last item in the list --> [lindex $myList end]
- extract the number [lindex [split item "_"] end]
- increment the number
- return it

Ultimately, it's not much more than a few lines of code.

Jeff

From: d on
That is basically what I did. For some reason, it struck me as
something that should have a more direct way to do it. Thank you for
your time.