The File component empowers the NewBASIC author with the means to view and manipulate files on a hard disk with a set of input/output actions.
name as string
The name of the current file on disk to view or change. Setting this property should happen soon after the creation of a file component and will be the string passed to system libraries to attempt access to the file.
size as integer
The size of the current file on the disk. Setting this property performs a truncation operation on the current file with the given integer.
date as integer
The date of the file is read off the disk and converted to an integer. Setting this property calls FileSetDateTime() on the current file. This integer value is stored as a FileDate structure.
time as long
The file timestamp is stored as a 32-bit double word according to the New Deal FileTime format.
trap as integer
The trap property specifies what the file component should do when it encounters an error. The following table maps out trap behavior for the file component:
0 ignore file errors and continue
1 call the runtime error handler (not supported yet)
2 create a dialog box informing the user about the error and proceed
error as integer
This property returns the error code of the last file error that occured. Setting this property forces the given file error to occur and initiates a response as specified in the trap property.
const ERROR_UNSUPPORTED_FUNCTION 1
const ERROR_FILE_NOT_FOUND 2
const ERROR_PATH_NOT_FOUND 3
const ERROR_TOO_MANY_OPEN_FILES 4
const ERROR_ACCESS_DENIED 5
const ERROR_INSUFFICIENT_MEMORY 8
const ERROR_INVALID_VOLUME 15
const ERROR_IS_CURRENT_DIRECTORY 16
const ERROR_DIFFERENT_DEVICE 17
const ERROR_NO_MORE_FILES 18
const ERROR_WRITE_PROTECTED 19
const ERROR_UNKNOWN_VOLUME 20
const ERROR_DRIVE_NOT_READY 21
const ERROR_CRC_ERROR 23
const ERROR_SEEK_ERROR 25
const ERROR_UNKNOWN_MEDIA 26
const ERROR_SECTOR_NOT_FOUND 27
const ERROR_WRITE_FAULT 29
const ERROR_READ_FAULT 30
const ERROR_GENERAL_FAILURE 31
const ERROR_SHARING_VIOLATION 32
const ERROR_ALREADY_LOCKED 33
const ERROR_SHARING_OVERFLOW 36
const ERROR_NETWORK_CONNECTION_BROKEN 55
const ERROR_NETWORK_ACCESS_DENIED 65
const ERROR_NETWORK_NOT_LOGGED_IN 78
const ERROR_SHORT_READ_WRITE 128
const ERROR_INVALID_LONGNAME 129
const ERROR_FILE_EXISTS 130
const ERROR_DOS_EXEC_IN_PROGRESS 131
const ERROR_FILE_IN_USE 132
const ERROR_ARGS_TOO_LONG 133
const ERROR_DISK_UNAVAILABLE 134
const ERROR_DISK_STALE 135
const ERROR_FILE_FORMAT_MISMATCH 136
const ERROR_CANNOT_MAP_NAME 137
const ERROR_DIRECTORY_NOT_EMPTY 138
const ERROR_ATTR_NOT_SUPPORTED 139
const ERROR_ATTR_NOT_FOUND 140
const ERROR_ATTR_SIZE_MISMATCH 141
const ERROR_ATTR_CANNOT_BE_SET 142
const ERROR_CANNOT_MOVE_DIRECTORY 143
const ERROR_PATH_TOO_LONG 144
const ERROR_ARGS_INVALID 145
const ERROR_CANNOT_FIND_COMMAND_INTERPRETER 146
const ERROR_NO_TASK_DRIVER_LOADED 147
const ERROR_LINK_ENCOUNTERED 148
const ERROR_NOT_A_LINK 149
const ERROR_TOO_MANY_LINKS 150
buffer as component
This returns a memory caching fileBuffer component. This behavior is experimental, and simply provides the following ANSI-C-like interface at this time.
eof as integer
This property stores a boolean value indicating whether or not the end of file has been reached. This property works well as the conditional of loops such as while and until. Often directly checking this property can be avoided by employing the .ends() or .goes() actions.
data complex
This value stors the actual graphics string as a complex. This value can be passed to other components when setting their .graphic properties.
This action opens the current file for access. Upon encountering an error, open() returns a FileError.
This action closes the current file. Upon encountering an error, close() returns a FileError.
This action deletes the current file. Upon encountering an error, delete() returns a FileError.
This action creates a new file under with the current name. Upon encountering an error, create() returns a FileError.
write(buffer as string, numchars as integer) as integer
Ths action writes numchars characters of string buffer to the current file.
This action returns the string of length N starting at the current position in the current file.
This action returns the byte at the current position in the file as an integer. The current position is read with tell(), set with go(N), and changed with seek(N).
Example: (read an entire file)
dim file as component
dim outputText as component
outputText = MakeComponent("text","top")
file = MakeComponent("file","top")
file.name = "test.txt"
file.open()
while file.goes()
outputText.AppendString(Chr(file.peek()))
loop
file.close()
poke(character as integer) as integer
This action writes the passed character to the current position in the file.
move(path as string) as integer
This action moves the physical presence of the current file to the given path string.
dateline(N as integer) as integer
This action return a time stamp string of type N format where N is one of:
const DTF_LONG 1
const DTF_LONG_CONDENSED 2
const DTF_LONG_NO_WEEKDAY 3
const DTF_LONG_NO_WEEKDAY_CONDENSED 4
const DTF_SHORT 5
const DTF_ZERO_PADDED_SHORT 6
const DTF_MD_LONG 7
const DTF_MD_LONG_NO_WEEKDAY 8
const DTF_MD_SHORT 9
const DTF_MY_LONG 10
const DTF_MY_SHORT 11
const DTF_YEAR 12
const DTF_MONTH 13
const DTF_DAY 14
const DTF_WEEKDAY 15
const DTF_HMS 16
const DTF_HM 17
const DTF_H 18
const DTF_MS 19
const DTF_HMS_24HOUR 20
const DTF_HM_24HOUR 21