question about open function

2009-05-14
2012-11-23
  • Jack  Widman
    Jack Widman
    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))

     
    • Jack  Widman
      Jack Widman
      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.

       
    • Jack  Widman
      Jack Widman
      2009-05-15

      Sorry about that. I feel silly.