Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detecting an ASCII text file

Posted on 1997-11-20
2
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 150 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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