---
title: "BinaryFile (_BinaryFile class)"
canonical: "https://docs.cuesystem.com/space/CVCHELP/510591213/BinaryFile%20(_BinaryFile%20class)"
format: markdown
---
> Macro (toc)

---

# Close 

This function closes the file for that instance _BinaryFile. Over a closed file cannot perform any functions except Open. See <u>examples</u>. 

#### Syntax 

```visualbasic
Function Close()
```

# Copy 

This function copies the current contents of an opened file to the destination file. If the destination file does not exist, it is automatically created. If it exists and the parameter eraseexisting is false, then the copy will fail. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[78](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#78)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>, <u>[104](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#104)</u>, <u>[105](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#105)</u>, <u>[106](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#106)</u>, <u>[107](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#107)</u>, <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[110](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#110)</u>. 

#### Syntax 

```visualbasic
Function Copy( 
  destinationfilepathname As Text, 
  Optional eraseexisting As Boolean := True) 
As Boolean
```

#### Parameters 

destinationfilepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the destination file. See <u>[rules of names of files and folders](/wiki/spaces/CVCHELP/pages/512983041/Files+folders#NamesOfFilesAndFolders)</u>. 

eraseexisting 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> Optional, defaults to True. If it is True, the existing file is erased. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# EraseContent 

This function deleted file contents. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[78](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#78)</u>, <u>[102](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#102)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>. 

#### Syntax* *

```visualbasic
Function EraseContent() As Boolean
```

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# GetPathName 

This function returns the path to an opened file in its entirety, including the directory name. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[78](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#78)</u>, <u>[80](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#80)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>. 

#### Syntax 

```visualbasic
Function GetPathName(ByRef filepath As Text) As Boolean
```

#### Parameters 

filepath 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the destination file. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# Open 

This function opens a file in reading and write mode and sets the position to start. The file is always opened exclusively. If the file does not exist, it is automatically created. If there is no directory structure, it is automatically created. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[77](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#77)</u>, <u>[79](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#79)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>, <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[110](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#110)</u>, <u>[111](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#111)</u>, <u>[119](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#119)</u>. 

#### Syntax 

```visualbasic
Function Open(filepathname As Text) As Boolean
```

#### Parameters 

filepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the file. See <u>[rules of names of files and folders](/wiki/spaces/CVCHELP/pages/512983041/Files+folders#NamesOfFilesAndFolders)</u>. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# OpenReadOnly 

This function opens a file in read-only mode and sets the position to start. If the file does not exist, one is not created and the function returns False. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[77](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#77)</u>, <u>[79](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#79)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>, <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[110](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#110)</u>, <u>[111](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#111)</u>, <u>[119](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#119)</u>. 

#### Syntax 

```visualbasic
Function Open(filepathname As Text) As Boolean
```

#### Parameters 

filepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the file. See <u>[rules of names of files and folders](/wiki/spaces/CVCHELP/pages/512983041/Files+folders#NamesOfFilesAndFolders)</u>. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# Read 

This function reads the optional number of bytes from a file. A file position is shifted by the number of bytes read. If the specified number of bytes numofbytes = 0, then reads as many bytes as there is capacity destinationbytestring. When the end of the file is reached False is returned. If reading fails for other reasons, False is returned.  See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[78](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#78)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>, <u>[112](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#112)</u>. 

#### Syntax 

```visualbasic
Function Read( 
  ByRef destinationbytestring As ByteString, 
  Optional numofbytes As Long := 0) 
As Boolean
```

#### Parameters 

destinationbytestring 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination bytestring. 

numofbytes 

<u>[Long](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> Optional, defaults to 0. It is the number of bytes to read. If it is 0, then reads as many bytes as there is a capacity destinationbytestring. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# Write 

This function writes the value of the source bytestring at end of the file. See <u>examples</u>. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[78](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#78)</u>, <u>[103](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#103)</u>, <u>[115](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#115)</u>. 

#### Syntax 

```visualbasic
Function Write(sourcebytestring As ByteString) As Boolean
```

#### Parameters 

sourcebytestring 

<u>[ByteString](/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the bytestring to write. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

# Examples 

#### Reading/writing text data 

```visualbasic
Var CfgBinaryFile As _BinaryFile 
Var CfgData As ByteString[100] 

If CfgBinaryFile.Open("/filestorage/cfg.txt") Then 
  CfgBinaryFile.EraseContent() 
  CfgBinaryFile.Write(&S"Hello, how are you?") 
  CfgBinaryFile.Close() 
End If 

If CfgBinaryFile.Open("/filestorage/cfg.txt") Then 
  CfgBinaryFile.Read(CfgData) 
  CfgBinaryFile.Close() 
End If
```

#### Copy 

```visualbasic
Var CfgBinaryFile As _BinaryFile 

If CfgBinaryFile.Open("/filestorage/cfg.txt") Then 
  CfgBinaryFile.Copy("/filestorage/cfg2.txt") 
  CfgBinaryFile.Close() 
End If
```

#### GetPathName 

```visualbasic
Var CfgBinaryFile As _BinaryFile 
Var FilePath As Text[100] 

If CfgBinaryFile.Open("/filestorage/cfg.txt") Then 
  CfgBinaryFile.GetPathName(FilePath) 
  CfgBinaryFile.Close() 
End If
```