Solved

Detecting an ASCII text file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 125
tidtcpserver connection lost handle 2 71
Dynamically Created Query 3 50
Firemonkey DbLookupComboBox equivalent ? 2 37
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…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

12 Experts available now in Live!

Get 1:1 Help Now