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         |     [EMAIL PROTECTED]
HyperActive Software           |     http://www.hyperactivesw.com
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to