Tcl open command

  • Creator
    Topic
  • #50365
    Mark Perschbacher
    Participant

    I am playing around with a proc, trying to get it to append some data to the beginning of an existing file.  With the value of “a” or “a+”  for the access argument, I can get it to append at the end of the file.  Does anyone know of a way to append the data to the beginning?

Viewing 4 reply threads
  • Author
    Replies
    • #65777
      Rob Abbott
      Keymaster

      You can use seek to get the pointer to the beginning of the file.  But I think any data written will over-write existing data, not prepend.

      You might try something like this:

      Code:

      set new_data “this is new data, which should be prepended”
      set filename foo.txt
      set existing_data [read_file $filename]
      write_file $filename ${new_data}${existing_data}

      Rob Abbott
      Cloverleaf Emeritus

    • #65778
      Mark Perschbacher
      Participant

      Rob, that did the trick.  I seriously don’t know what I would do without the huge braintrust that is Clovertech, thanks

    • #65779

      I totally cheat when I need to do this. Instead of using the tcl file functions, I use cat, perl, whatever system commands I need.

      Example:

      Code:

      exec echo “foobar” >> /path/file.txt

      -- Max Drown (Infor)

    • #65780
      Mark Perschbacher
      Participant

      We run Clovleaf in a Windows environment.  When I run that command at the tcl prompt, I get a “couldn’t execute echo, no such file or directory error.

    • #65781

      You’d have to have the unix utilities installed.

      -- Max Drown (Infor)

Viewing 4 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10