determining a plain text file
J. Landman Gay
jacque at hyperactivesw.com
Sun Jul 9 17:16:14 EDT 2006
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 hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list