Reference Manual - Table of Contents

Execution Control
Forms and Windows
Controls
Menus
System and Desktop
Graphic Drawing Commands

Animation
QuickTime Movies
Speech
Sound
File I/O
Printing
Serial Ports

Math Functions
String Functions
Date and Time
Memory Buffers
Error Handling
Console Text Window

Events

Direct Memory Access
Direct Mouse Access
Direct Keyboard Access
Code Resource Modules

A - Runtime Error Messages
B - Compiler Error Messages

 

File I/O

This section describes the commands and functions that can manipulate data files.

Command Summary:
Open var, mode, pathname$
Close
FileID
Create
pathname$, creator, filetype
CreateFolder
pathname$
Delete
pathname$
Rename oldPathname$, newName$
CopyFile
srcFilename$, destFilename$
Lock
pathname$
Unlock
pathname$
Write
FileID, text$
WriteBuffer
FileID, BufferID, StartLocation, NumberOfBytes
ReadBuffer
FileID, BufferID, StartLocation, NumberOfBytes
Seek
FileID, location

Function Summary:
var$ = OpenDialog ( fileTypes$ )
var$ = SaveDialog ( pathname$, prompt$ )
var$ = Read ( FileID, NumberOf Bytes )
var$ = LineInput ( FileID )
var = ReadBuffer( FileID, BufferID, StartLocation, NumberOfChars )
var = LOF ( FileID )
var$ = Dir ( pathname$ )
var = NumFiles ( pathname$ )
var$ = GetFilename ( pathname$, file# )
var = EOF ( FileID )
var = LOC ( FileID )
var = FileExist ( pathname$ )
var = FileName ( pathname$ )
var = FileSize ( pathname$ )
var = TypeCvt ( fileType$ )

 

Open var, mode, pathname$

This command will open a file for read and write operations. You can use the OpenDialog( ) and SaveDialog( ) functions to have the user select a filename.

File Open Options
1 - Read Exclusive Permission
2 - Write Exclusive Permission
3 - Exclusive Read/Write Permission
4 - Shared Read/Write Permission

Close FileID

This command will close a file that was previously open with the OPEN command.

Create pathname$, creator, filetype

This command will create a new empty file. If there is an existing file with the same pathname then it will delete it and create a new empty file.

.

Use the TypeCvt() function to help in converting text in to a numeric format. The following is an example of creating a empty text file that when clicked on will launch TeachText or SimpleText:

Example:

Create "TextFile", TypeCvt( "ttxt"), TypeCvt( "TEXT")

 

CreateFolder pathname$

This command will create a new folder.

pathname$ - This should be a string expression that contains the name of the folder that is to be created.
For example: Harddisk:MyNewFolder

 

Delete pathname$

This command will delete an existing unopened file or folder.

pathname$ - This should be a string expression that contains the name of the file that is to be used. If the file is not located in the current default directory then you must specify the directory path specification.
For example:

Harddisk:MyFolder:MyFile

 

Rename oldPathname$,newName$

This command will rename an existing unopened file or a folder .

CopyFile Pathname1$, Pathname2$

This command will copy a file. Both the data and resource forks of the file will be copied.

Lock pathname$

This command will lock an existing file.

Unlock pathname$

This command will unlock an existing file.

Write FileID, text$

This command will write data from the text$ expression to a file.

.

WriteBuffer FileID, BufferID, StartLocation, NumberOfChars

This command will write data from a buffer to a file.

Seek FileID, location

This command will move the file position pointer.

var$ = OpenDialog( fileTypes$ )

This function will allow the user to select a filename from the standard Open File Dialog for later file operations. This function returns a pathname it does not open the file.



Example:

Dim a$

' Filter for only 'TEXT' and 'rsrc' file types
a$ = OpenDialog( "TEXTrsrc" )

 

var$ = SaveDialog( pathname$, prompt$ )

This function will allow the user to select or enter a filename in the Save File Dialog for later save operations. Once the user selects the SAVE button in the dialog the string variable var$ will contain the pathname. This variable will be empty (equals "") if the user canceled and no file was selected.

var$ = Read( FileID, NumberOfChars )

This function will return a string containing data read from an open file.

var$ = LineInput( FileID )

This function will return a string containing the next line (to the next carriage return (CR) , linefeed(LF), or up to 300 characters) read from an open file.

This function is for reading text lines from a file. It will not include the carriage return or linefeed characters, these characters will be skipped for reading of the next line with this function. If 300 characters are read without a carriage return and/or linefeed then a string containing the 300 characters will be returned.

var = ReadBuffer( FileID, BufferID, StartLocation, NumberOfChars )

This function will read from an open into a buffer. The value that this function returns is the number of bytes actually read from the file.

 

var = LOF( FileID )

This function will return a numeric value indicating the length of a file opened with the Open command.

var = EOF( FileID )

This function will return a numeric value indicating whether the file position pointer is at the end of the file.

var = LOC( FileID )

This function will return the file position pointer of a file opened with the Open command.

var$ = Dir( pathname$ )

This function will return a string value containing the file & folder names from the specified folder. Use the NumFiles and GetFileName functions to retrieve information from the returned string value. This string may contain up to 500 file/folder names. Please note that if you store this value in a string variable, that string variable must be allocated 32000 bytes to avoid possible truncation of the string.

pathname$ - This should be a string expression that contains the name of the folder that is to be used.

Examples: 
Dim D$[32000], CTR, F$
D$ = Dir("Harddisk:MyFolder")
Print "Number of Files=",Numfiles(D$)
For CTR=1 to Numfiles(D$)
Print GetFilename( D$, CTR)
Next CTR
'another way 
CTR = NumFiles( Dir("Harddisk:MyFolder"))

var = NumFiles( dirString$ )

This function will return the number of files/folders in the dirString$, returned from the Dir( ) function.

dirString$ - This should be a string value returned from the Dir( ) function.

var$ = GetFilename( dirString$, file# )

This function will return a file/folder name from the dirString$, returned from the Dir( ) function.

dirString$ - This should be a string value returned from the Dir( ) function.

file# - This should be a numeric value to specify the which file in the dirString to return. It should less or equal to the value return from the NumFiles( ) function..

var = FileExist( pathname$ )

This function will return a value indicating whether a file exists.

var = FileSize( pathname$ )

This function will return a value indicating the length of an unopened file. This value includes both the Data and Resource forks of the file. The LOF() function only returns the size of the Data fork.

var$ = FileName( pathname$ )

This function will return text string that is just the filename part of a pathname$. In the example below it woulfd return just "MyFile".

var =TypeCvt( text$ )

This function will return a value that converted from a 4 character long text string that represents a creator or filetype code. See the Create command for an example of this function.