Welcome Guest | My Membership | Login

Read and Writing Windows files from D3

Downloads

Article

Reading and Writing to Windows files is pretty simple within MultiValue Database application This article talks about SUBROUTINE (Store procedures) that can be used to make your job easier. The routines included in this article have a few limitations that you need to be aware of, though. They will read the complete Windows Files into memory as a dynamic array. This is not a problem with small files, but if you are working with large file (3MB, 4MB, or 10MB), it can become a problem. If you need to work with large files, then you will need to read the file in chunks, which is another article all together.

Another limitation has to do with binary data or blobs. MultiValue Database are designed to handle business data for storage, processing, reporting, mining, as well as other business tasks. Since binary data is unstructured and is generally stored in the OS File System, not the database, MultiValue SUBROUTINES (stored procedures) don't handle them well. If you want to know how to work with and store binary data within a MultiValue database, the please see the articles relating to Binary/Blob data.

The following program will show you how to use the SUBROUTINEs provided in this article to access Windows files.

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("C:\temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
END


This TCL (Console) program will return an output similar to:

:!echo testing temp.txt > c:\temp\temp.txt
:!echo Line 2 of temp.txt >> c:\temp\temp.txt
:!type c:\temp\temp.txt
Testing temp.txt.
Line 2 of Temp.txt
:EXAMPLE
Testing temp.txt.^Line 2 of Temp.txt
:

Something to Note, the CRLF are changed into AM marks (char 254). This allows you to access the information using standard dynamic array commands, include INSERT, DELETE, REPLACE, and LOCATE.

When you need to write to an OS file, it is just as simple as when reading.

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("c:\temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
*
TEMP.ITEM<3> = "Line 3 ": TIMEDATE()
CALL IS.WRITE.OS("C:\temp",TEMP.ITEM.FILE.NAME,ERROR.ITEM)
END

This will add a 3rd line to the /temp/temp.txt file. Using the 'cat' command you can see the results:

:!type c:\temp\temp.txt
Testing temp.txt.
Line 2 of Temp.txt
Line 3 15:45:19  08 Jun 2011


The command line above is using Windows syntax for creating the temp.txt file, but you can do the similar things using windows. Here is an example using Unix/Linux Syntax:

* Example
FILE.NAME = "temp.txt"
CALL IS.READ.OS("/temp",TEMP.ITEM,FILE.NAME,ERROR.ITEM)
IF ERROR.ITEM<1> > 0 THEN CRT "Error Reading ": FILE.NAME
*
CRT TEMP.ITEM
END


 

# # #          # # #          # # #

 

Related Articles


Return to top