Solved

Detecting an ASCII text file

Posted on 1997-11-20
2
151 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now