Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/* This code reads an existing OS file and copies it in 100 character chunks to a new OS file */
 
Equ RECSIZE$ To 100
readOffset = 0
writeOffset = 0
 
filename = "c:\temp\my_data.txt"
newFileName = "c:\temp\my_new_data.txt"
 
oswrite "" To newFileName ; * create the new file
 
OSOpen filename To inputFileHandle then
  OSOpen newFileName To outputFileHandle Then
    Loop
      OSBRead data From inputFileHandle At readOffset length RECSIZE$
      error = status()
    Until data = NULL$
      readOffset += RECSIZE$
      OSBWrite data On outputFileHandle At writeOffset
      writeOffset += RECSIZE$
    Repeat
  end else
    error = status()
  end
End else
  error = status()
End
 
osclose inputFileHandle
osclose outputFileHandle

 

 

Example 2

Code Block
/*  The following example shows how to use BASIC+ to handle operating system files.  */
* Open the test file, or, if it does not exist, create it.
OSOpen "OSTEST" To file_var Else
  * Create an operating system file.
  OSWrite "" To "OSTEST"
  * Create the necessary file handle.
  OSOpen "OSTEST" To file_var Else
    * error handling
  End
End
/* You might have reason to check a particular segment of data in an operating system file, as for example when looking at a data file header for which you know the length. In the following line, the desired segment is presumed to be 256 bytes in length, beginning at the first byte of the file. */
OSBRead data_segment From file_var At 0 length 256
/* Having the 256-byte segment within OpenInsight for Workgroups, you can now check particular locations for required information. The following code looks for the string "Revelation Software" within the 256-byte segment. */
search = "Revelation Software"
start = Index(data_segment, search, 1)
if start then
  found = data.segment [start, len(search)]
* The found string is converted to uppercase
Convert @LOWER_CASE To @UPPER_CASE in found_data
/* The converted string is now written directly back to the OS file. */
OSBWrite found_data On file_var at start
end
OSClose file_var