Loading ...
Sorry, an error occurred while loading the content.

23486Re: [Clip] Re: Would like better way to increment filename by one

Expand Messages
  • Ian NTnerd
    Dec 4, 2012
    • 0 Attachment
      On 5/12/2012 6:46 AM, joy8388608 wrote:
      > Very interesting thoughts from everyone and I'm kind of happy that
      > there have been no "why didn't *I* think of that" answers so far.
      > To clarify some things...
      > "bkup" was just an example. I want a routine that works with any and
      > all file names.
      > For this same reason, starting numbering with 10000 and using an
      > underscore to make the number easier to find is not an option.
      > I do very much agree with Axel in that clear, plodding code that can
      > be easily understood is usually better than shorter, "clever" code
      > that is difficult to follow. That and lots of comments! Anyone who has
      > had to modify other people's code know what I'm talking about.
      > Other languages have numeric formatting and special commands that
      > would make this easy but NT does not. So, for now, I think what I have
      > is the best I've come across unless someone comes up with an idea. My
      > code is not available to me at this moment but I'd be happy to post
      > what I have later if anyone has an interest. Just ask.
      > I'll be still thinking about this one.
      > Thanks!
      > Joy
      Sorry my last post had junk in it. Let me know what you think. I'd like
      to see what you have now.


      ^!SetDebug Off
      ; Get the file name (no path or extension)
      ^!set %input%=^&
      ; start loop from ClipHelp.clb
      ^!Set %Index%=0
      ^!Set %LoopCount%=10
      ^!IfCancel End
      ^!Inc %Index%
      ^!If ^%Index% > ^%LoopCount% EndLoop
      ; test if the string that is ^%index% chars long is a number if not end loop
      ^!if ^$IsNumber(^$StrCopyRight("^%input%";^%index%)$)$=0 endloop
      ; create a string of zeros to be longer than needed
      ^!set %zeros%=^%zeros%0
      ; return to ClipHelp.clb closing section
      ^!GoTo LoopStart

      ; test if the ^%index% is 1, if it is then there is no number at the
      end. Do nonumber else do has number.
      ^!if ^%index%=1 nonumber else hasnumber
      ; if no number create the string to return
      ^!set %return%=^%input%01
      ^!goto return
      ; if number found, decrease the index to the correct figure.
      ^!dec %index%
      ; get the non number part of the string
      ^!set %alpha%=^$StrDeleteRight("^%input%";^%index%)$
      ; get the number part and increase it by one
      ^!set %numb%=^$StrCopyRight("^%input%";^%index%)$
      ^!inc %numb%
      ; set the return value with alpha part and new number trimed to the
      input length.
      ; this will fail if your input string is 99 and it is increased to 100
      ^!set %return%=^%alpha%^$StrCopyRight("^%zeros%^%numb%";^%index%)$
      ^!result ^%return%

      ^$incfile(^?[Word to use=word0101010108])$

      [Non-text portions of this message have been removed]
    • Show all 13 messages in this topic