determining a plain text file

Dan Shafer revolutionary.dan at
Sun Jul 9 18:10:50 CDT 2006

The file name approach will work but it does rely on the person or program
creating the file to provide a correct file extension. Some files I might
characterize as plain text might have different extensions (most notably
HTML files which are all pure text but tagged information).

To be sure the file you're dealing with has only ASCII text characters in
it, you'd need to read it into some variable and then use chartonum to see
if any character in the file has an ASCII value higher than 128 (or whatever
you decide to define as the upper boundary of ASCII).

On 7/9/06, J. Landman Gay <jacque at> wrote:
> Scott Morrow wrote:
> >
> > Does anyone have a method for determining whether a file is plain text
> > that they would be willing to share?
> On most platforms, you can just check whether the last four characters
> of the file name are ".txt". On MacOS and OS X you should probably also
> check the file type, since Mac files don't always have an extension.
> However, note that many OS X apps do not set creator/type codes when
> creating new files, so you may find that some files have creator/type
> codes of "????????". In this case, you've got to rely on the extension
> if there is one.
> To check the file type, set the defaultFolder to the folder that
> contains the file. Then get "the detailed files" and parse the resulting
> list to find the file you want to know about. The last item in the line
> will be the file type and creator code, and the first four characters of
> that should be "TEXT" if it is really a text file.
> Here is one way to do it:
> function getFileType
>    answer file "Choose a file:"
>    if it = "" then return empty
>    set the itemdel to slash
>    put last item of it into tFileName
>    put item 1 to -2 of it into tFolder
>    set the itemDel to comma
>    put urlEncode(tFileName) into tFileName
>    set the defaultFolder to tFolder
>    put the detailed files into tFileList
>    put line lineoffset(tFileName,tFileList) of tFileList into tFileInfo
>    return (char 1 to 4 of last item of tFileInfo = "TEXT")
> end getFileType
> --
> Jacqueline Landman Gay         |     jacque at
> HyperActive Software           |
> _______________________________________________
> use-revolution mailing list
> use-revolution at
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:

Dan Shafer, Information Product Consultant and Author
Get my book, "Revolution: Software at the Speed of Thought"

More information about the use-livecode mailing list