There are occasions when the technician needs to determine specific types from a list of files. The attribute scrutiny alone is not reliable because file specifications are not normally associated by attributes. After closely examining text files there are attributes that distinguish them from other file types.
One distinguishing characteristic is the end of file marker for a text document. The end of document marker is a hexadecimal value of "10" or in hexadecimal notation "$A" (minus double quotes).
Initially we set the result for the text detection function to false. This tells the user the specification in question is not a text doc. There are a couple of considerations prior to reading the last character on the file and determining its value. The first consideration its size. To determine attributes the GetFileInformation method is invoked. This method returns information about the specification in standard search record format. The search record format is familiar to anyone who has dealt with file specifications or searching for a file or group of files based on a given file specification.
The second consideration is how to access the files contents in a non intrusive and non disruptive way. Here we will introduce the BlockRead statement of the standard IO routines. Prior to invoking the block read we must describe the file specification by using the AssignFile procedure of the IO routines. To describe the file's physical characteristics we use the Reset procedure with the file name and size argument. In this case we will use one for the logical record size. This tells the IO routines that the assigned file is a collection of records that are one character in length.
Next we need a fast way to position us to the proper location to read the last character of the document. We accomplish this by using the seek statement. The seek statement takes two parameters. The first the file handle and the second is the position in the doc. By using the file size minus one we determined from the GetFileInformation routine mentioned earlier we position our routine to read the last character in the file.
Finally we invoke the BlockRead and access the last character in the file. We store its contents in a storage buffer, close the associated file handle then compare the stored contents against the "$A" constant we are looking for(minus double quotes). If the compare results are true then we set the results for the text file detection routine to true.
Mr. Arch Brooks, Software Engineer
http://archbrooks.com
Article Source: http://EzineArticles.com/?expert=Arch_Brooks
Arch Brooks - EzineArticles Expert Author
Friday, June 5, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment