Solved

Detecting an ASCII text file

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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