The file access package

Contents


Overview


The package hbasic_file provides the components and methods to work with LINUX files and directories. This includes the following four components:

FILE Read and write access to files (see example)
FILEDLG Call QFileDialog to ask user for filename
FILEINFO Get Info about files (QFileInfo)
DIRINFO
Get Info about directory structures and their contents (QDirInfo)


Methods of component File


The file component may be used to read or write data to a file. To get some information about a file use the FileInfo component.

The following methods may be used with a component of type file:
Open Open a file for reading or writing
Close Close a file
Eof Check if end of file has been reached.
read( long ) read values in ASCII format from file
readline read until end of line has been reached.
write Write values as ASCII text to a file
writeline Write a string with CR to file
getbyte Get a numerical value with 1 byte length from a file
getint Get a numerical value with short length from a file
getlong Get a numerical value with long length from a file
getdbl Get a double value from a file
getstr Get String of special length from file
getxstr get string from file in extended format
put Write binary value to file
putstr Write string to file
putxstr Write string in extended format to file.


File example


The following example opens a file in write-mode and writes the numbers from 1 to 20 to it.

Public f As file
Public i As Long

Sub button1_clicked()
   f.open( "test.dat", "w" )
   i = 1
   While i < 20 Do
      f.write( "Value = "+str(i))
      i = i + 1
   Wend
   f.close()
End Sub
Example ex_comp_file.bas: Open file and write data to it


Methods of component FileDialog

The FileDialog component can be used to show an additional dialog where the user can select the name of a file that he wants to use. The following methods may be used with a component of type FileDialog:

GetOpen Print a value of type long (integer or byte)
GetSave Print a value of type double
GetDir Print s string


Methods of component FileInfo

The FileInfo component may be used to gather information about a special file. You first have to create a file component and call the method fileinfo.setFile( filecomp) with this fileinfo component.

setfile Print a value of type long (integer or byte)
path Print a value of type double
basename Print s string
filename
Clear the current window contents


Methods of component DirInfo


The DirInfo component provides information about the structure and contents of a LINUX directory. It may be used to create or delete directories and query for general information about directories.

The following methods may be used with a component of type DirInfo:

setPath Set the path of a directory that should be used with the DirInfo component.
currentdir Get the value of the current directory.
setcurrent Set a new path for the current directory.
GetHome
Get the home directory for the current user.