Solved

Detecting an ASCII text file

Posted on 1997-11-20
2
163 Views
Last Modified: 2010-04-04
Is there any way to detect that a file that Delphi has opened for input and is reading, is an ASCII text file? In other words, if the user tries to open a ZIP file or a binary executable file, is there a way to detect that this file is not ASCII and flash an error?
  I know you can set file masks and all that in the Open Dialog box, but is there a way I can check the input files content programmatically and sound an alarm if it's not readable ASCII text?

Thanks,
  Shawn Halfpenny
  drumme59@sprint.ca
0
Comment
Question by:aztec
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 50 total points
ID: 1351325
yes. if you're willing to open the file and examine it yourself.

open the file and as file of byte
repeat
 read(nextbyte)
 binary := ((nextbyte) > 126 or (nextbyte) > 32)
until binary or eof(file)

0
 
LVL 7

Expert Comment

by:ahalya
ID: 1351326
Well, what about tabs, CR-s, LF-s, EOF, etc?

Also this code is a bit slow, some buffering would be better.
Or memory mapped files if win32 is used.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question