*File Keywords*

Back to the start


AppPath
DirCreate
DirDel
DirExist
DirSearch
FileClose
FileCopy
FileDel
FileDirName
FileExist
FileGet
FileGetByte
FileName
FileOpen
FilePut
FilePutByte
FileRead
FileReadToEnd
FileSearch
FileSize
FileWrite


AppPath Top

Returns the path of the application.
Syntax: AppPath

DirCreate Top

Creates a new folder.
If the folder already exists, nothing will happen.
Syntax: DirCreate (Folder Path)
Example:
DirCreate ("Images")

This will create a folder named Images inside the application folder. (The source code or the compiled file folder)

DirDel Top

Deletes the specified folder
Syntax: DirDel (Path [,Including Files])
Including Files can be True or False.
If Including Files is omitted or set to False DirDel will delete only empty folders.
Example:
DirDel ("Images", False)

DirExist Top

Checks if a specific folder exists and returns true or false.
See External Files for information about file path.
Syntax: DirExist (Folder Name)
Example:
If DirExist ("Images") = True Then ...

DirSearch Top

Adds all subdirectories matching the search pattern in the specified path to an ArrayList and returns the number found.
Syntax: DirSearch (ArrayList, Path [,Search Pattern])
If the Search Pattern is omitted DirSearch will return all the subdirectories in the directory.
Search Pattern can include '*' and '?'.
* - Finds zero or more characters.
? - Finds exactly one character.
Example: (alDir is an ArrayList control)
FileSearch (alDir, "\My Documents")

This example will add all the subdirectories in My Documents folder (in the device) to the ArrayList alDir.

FileClose Top

Closes a file connection.
Syntax: FileClose (Connection Name)
See FileOpen for more information.

FileCopy Top

Copies a file.
Syntax: FileCopy (Source File, Target File [,Overwrite])
Overwrite default is true which means it will overwrite the target file if it exists.
Example:
If OpenDialog1.Show <> cCancel Then
 FileCopy (OpenDialog1.File, FileName(OpenDialog1.File))
End If

This example will copy the file chosen by the user to the current application path.

FileDel Top

FileDel deletes a file.
Syntax: FileDel (FileName)
Example: FileDel ("file.txt")

FileDirName Top

Returns the file path without its name.
Syntax: FileDirName (File)

FileExist Top

Checks if a specific file exists and returns true or false.
See External Files for information about file path.
Syntax: FileExist (File Name)
Example:
If FileExist ("myFile.txt") = true Then FileOpen (c,"myFile.txt",cRead)

FileGet Top

FileGet reads a number or a string from a specific position in an opened file connection.
Syntax: FileGet (Connection name, Position [,String length])
Position is the number of bytes from the beginning of the file where the data is taken from.
If you don't provide String Length then FileGet returns a number.
Each number is saved in 8 bytes format.
If you provide the String Length then FileGet returns a string in the specific length.
To get the file size (in bytes) use FileSize keyword.
Example:
FileOpen (c1, "data.dat",cRandom)
x = FileGet (c1, 16) 'x value will be of the third number stored in the file
FileClose(c1)

Example:
FileOpen (c1, "text.dat",cRandom)
s = FileGet (c1, 5,10) 's will be a string with 10 characters starting from the sixth character in the file.
FileClose(c1)

FileGetByte Top

Returns the byte stored at a specific position.
Byte value can be 0 to 255.
Syntax: FileGetByte (Connection Name, Position)
To use FileGetByte / FilePutByte you need to first open the file as random.
Example:
FileOpen (c,"data.dat",cRandom)
b = FileGetByte (c,0) 'returns the first byte in the file.
FileClose (c)

FileName Top

Returns the file name without the path.
Syntax: FileName (File)
Example: Name = FileName (OpenDialog1.File)

FileOpen Top

To read or write to a file you need to first open a connection to it with FileOpen.
You can open a read-only connection, a write-only connection or a random access connection.
Connection name can be any word starting with a letter.
Later when you read or write to a file you'll use the connection name and not the file name.
When you finish working with a file it's important to close it in order to release the file lock.
Syntax: FileOpen (Connection Name, File Name, cRead | cWrite | cRandom [,cAppend [,cASCII])
cAppend is relevant to Write mode only and it means that if the file already exists then the data will be appended to its end.
If cAppend is not used then a new file will be created whether the file exists or not.
See External Files for information about file path.
The files opened can be treated as Unicode files or ASCII files.
Unicode files support many languages but not all applications support Unicode files.
Use the cASCII argument if you want to use ASCII files.
FileRead / FileReadToEnd / FileWrite are relevant to read-only or write-only connections.
FilePut / FileGet / FilePutByte / FileGetByte are relevant to random access connections.
Example:
If FileExist ("Data.txt") = true Then
 FileOpen (c1,"Data.txt",cRead ,, cASCII)
 r = FileRead (c1)
 Do Until r = EOF
   sum = sum + r
   r = FileRead (c1)
 Loop
 Msgbox (sum)
 FileClose (c1)
End if

Example:
FileOpen (c1,"Data.txt",cWrite,,cASCII)
FileWrite (c1,"20")
FileWrite (c1,"30")
FileWrite (c1,TextBox1)
FileClose (c1)

FilePut Top

FilePut writes a number or a string at a specific position in a file connection.
Syntax: FilePut (Connection name, Position, Text - True | False, String | Number)
Each number written captures 8 bytes.
Each letter in a string captures 1 bytes.
Example:
FileOpen (c1, "data.dat", cRandom)
FilePut (c1, 8, false, 2323313.2563) 'writes this number starting from position 8 to 15
FilePut (c1,16,true,"this is a string")'writes the text starting from position 16 to 31
FileClose (c1)

FilePutByte Top

Saves a byte in the specified position.
Byte value can be 0 to 255.
Syntax: FilePutByte (Connection Name, Position, Byte)
To use FileGetByte / FilePutByte you need to first open the file as random.
Example:
FileOpen (c,"data.dat",cRandom)
FilePutByte (c,0,100) 'Saves the value 100 at the first byte.
FileClose (c)

FileRead Top

Returns one line from an opened file.
Moves the pointer to the next line.
When it reaches the end of file it returns EOF constant.
Syntax: FileRead (Connection Name)
Example

FileReadToEnd Top

Returns all remaining data from an opened file. (starting from current pointer position)
Syntax: FileReadToEnd (Connection Name)

FileSearch Top

Adds all files matching the search pattern in the specified path to an ArrayList and returns the number of files found.
Syntax: FileSearch (ArrayList, Path [,Search Pattern])
If the Search Pattern is omitted FileSearch will return all the files in the directory.
Search Pattern can include '*' and '?'.
* - Finds zero or more characters.
? - Finds exactly on character.
Example: (alFiles is an ArrayList control)
FileSearch (alFiles, "\My Documents", "*.txt")

This example will add all the files with txt extension in My Documents folder (in the device) to the ArrayList alFiles.

FileSize Top

Returns the file length (number of bytes).
Syntax: FileSize (File)
Example:
FileOpen (c1, "Data.dat", cRandom)
MaxN = FileSize ("Data.dat")
For i = 0 to MaxN step 8
 ListBox1.Add (FileGet (c1,i))
Next
FileClose (c1)

This example will fill a listbox with numbers written in a file named Data.dat .

FileWrite Top

Writes a string to an opened file.
The string is written to the next line in the file.
If the string includes several lines (like a multiline textbox) then all the lines are written.
Syntax: FileWrite (Connection name, String)
Example