question about open function

  • Anonymous - 2009-05-14

    When I use 'open' to open a file, and then printout the length of the file, I get the wrong answer. Is there a bug related to this? Am I doing something silly?

    (open "my-file.txt" my-file "r")
      (printout t "The length of the file is " (my-file))

    • Anonymous - 2009-05-14

      That should have read

      (open "my-file.txt" my-file "r")
      (printout t "The length of the file is " (length my-file))

      I get the wrong answer with this code.

    • Gary Riley

      Gary Riley - 2009-05-15

      The length function returns the length of a symbol/string or multifield value. It doesn't recognized logical names in use by the file I/O function so passing in my-file is just going to return the length of that symbol, which is 7. To compute the size of a text file, you'd need to open the text file and read it line adding the length of each line to a running total.

    • Anonymous - 2009-05-15

      Sorry about that. I feel silly.


Log in to post a comment.