File name (amending first 3 characters)

Clovertech Forums Cloverleaf File name (amending first 3 characters)

  • Creator
    Topic
  • #122562
    bso its
    Participant

      Hi

      I have a script : to remove the characters WBS and replace with NIBTS

      proc set_outbound_name {args} {

      # Extract MODE safely
      if {[catch {keylget args MODE mode}]} {
      return “”
      }

      # ✅ Ignore startup call
      if {$mode eq “start”} {
      return “”
      }

      # Extract MSGID and ARGS safely
      if {[catch {keylget args MSGID msgid}]} {
      return “”
      }

      if {[catch {keylget args ARGS innerArgs}]} {
      set innerArgs {}
      }

      # ✅ Get driverControl (this is where FILENAME lives)
      set driverControl [msgget $msgid]

      # Extract filename from driverControl list
      if {[catch {keylget driverControl FILENAME fname}]} {
      return

        }

        set base [file tail $fname]

        # DEBUG (leave enabled for now)
        HciAlert -info “FINAL DEBUG: original filename = $fname”

        if {[string match “WBS*” $base]} {

        regsub {^WBS} $base “NIBTS” newbase

        set dir [file dirname $fname]
        set newfname [file join $dir $newbase]

        # ✅ Write back into driverControl
        keylset driverControl FILENAME $newfname

        # ✅ Save updated driverControl
        msgset $msgid $driverControl

        HciAlert -info “FINAL DEBUG: new filename = $newfname”
        }

        return

           

          But it doesnt work  -Any advice ?

          Thanks in advance

        Viewing 4 reply threads
        • Author
          Replies
          • #122563
            Jason Russell
            Participant

              I don’t see anything particularly wrong with the code. How is it not working? What is the echo of the $base going in and the $newbase coming out?

            • #122567
              Jim Kosloskey
              Participant

                Don’t you need to do a msgmetaget in order to get the DRIVERCONTROL keyed list?

                email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

              • #122568
                Jason Russell
                Participant

                  I missed that. You’re correct:

                  set myklst [msgmetaget $mh DRIVERCTL]
                  keylget myklst FILENAME fileName

                  Pretty sure I ganked that from another script before I understood keylget.

                • #122569
                  bso its
                  Participant

                    Thank you for the replies (much appreciated)

                    Will make amends and let you know.

                    The issue is that its not attaching the “new” file name so its failing by saying file name is blank

                    Thanks again

                  • #122570
                    bso its
                    Participant

                      Hi

                      I had a few errors in the code but below is a working tcl script :

                      proc set_outbound_name {args} {

                      set dispList {}

                      # Get mode
                      set mode “”
                      catch {keylget args MODE mode}

                      if {$mode ne “run”} {
                      return $dispList
                      }

                      # Get message ID
                      set msgid “”
                      catch {keylget args MSGID msgid}

                      if {$msgid eq “”} {
                      echo “DEBUG: MSGID missing”
                      return $dispList
                      }

                      # ✅ Get FULL existing DRIVERCTL
                      set driverControl [msgmetaget $msgid DRIVERCTL]

                      # Get original filename
                      set fname “”
                      catch {keylget driverControl FILENAME fname}

                      if {$fname ne “”} {

                      echo “DEBUG: Existing filename = $fname”

                      set base [file tail $fname]

                      if {[string match “WBS*” $base]} {

                      echo “DEBUG: WBS match found”

                      regsub {^WBS} $base “NIBTS” newbase

                      echo “DEBUG: New filename = $newbase”

                      # ✅ SAFE UPDATE — do NOT overwrite DRIVERCTL
                      keylset driverControl FILESET.OBFILE $newbase

                      # (optional but fine to keep)
                      catch {keylset driverControl OUTFILE $newbase}

                      # Save updated structure
                      msgmetaset $msgid DRIVERCTL $driverControl

                      echo “DEBUG: DRIVERCTL updated (OBFILE patched)”
                      }
                      }

                      # ✅ Correct return
                      lappend dispList “CONTINUE $msgid”

                      return $dispList
                      }

                      Thanks again for your help  – much appreciated

                       

                  Viewing 4 reply threads
                  • You must be logged in to reply to this topic.