Is it a text file?
Posted: Mon May 18, 2020 4:17 pm
What are the ways to tell, nowadays, if a file is a text file or not in Dyalog? Specifically, I want to know if I can potentially use ⎕CSV on a particular file. To this end I can hack up something like this mess:
No doubt there are shorter, better solutions. We could trap ⎕NGET, but I don't want to read the whole file as it could be large (I could have sworn ⎕NGET was enhanced to read X number of records, but that appears not to be the case).
No doubt there are also solutions using ⎕NREAD, but I think ⎕CSV is doing alot of work under the covers to determine the type of text file the thing is, so maybe its useful here.
Any solutions or hint or tips appreciated.
IsTextFile←{
⍝ ⍵ ←→ Filename
o←'Records' 64
t←⍵ ⎕NTIE 0
11::1⊣⎕NUNTIE t
92::0⊣⎕NUNTIE t
≢⎕NUNTIE t⊣(⎕CSV⍠o)t
}
No doubt there are shorter, better solutions. We could trap ⎕NGET, but I don't want to read the whole file as it could be large (I could have sworn ⎕NGET was enhanced to read X number of records, but that appears not to be the case).
No doubt there are also solutions using ⎕NREAD, but I think ⎕CSV is doing alot of work under the covers to determine the type of text file the thing is, so maybe its useful here.
Any solutions or hint or tips appreciated.