SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
File System Commands

Function: FREEFILE 0 Returns an unused file handle INPUT|OUTPUT|APPEND] AS #fileN Makes a file or device available for sequential input, sequential output. The files are always opened as shared.
Command: CLOSE #fileN Close a file or device
Command: TLOAD file, BYREF var [, type] Loads a text file into array variable. Each text-line is an array element.
Command: TSAVE file, var Writes an array to a text file. Each array element is a text-line.
Function: EXIST (file) Returns true if the file exists
Function: ACCESS (file) Returns the access rights of the file. The return-value is the permissions of the file as them as specified on GNU's manual (chmod() and stat() system calls) The bits (in octal):
04000 set user ID on execution
02000 set group ID on execution
01000 sticky bit
00400 read by owner
00200 write by owner
00100 execute/search by owner
00040 read by group
00020 write by group
00010 execute/search by group
00004 read by others
00002 write by others
00001 execute/search by others
PalmOS, The return value is always 0777. DOS, The return value is depended on DJGPP's stat() function. Possible Unix compatible. Windows, The return value is depended on Cygnus's stat() function. Possible Unix compatible.
IF ACCESS("/bin/sh") AND 0o4 THEN
    PRINT "I can read it!"
ENDIF

Function: ISFILE (file) Returns true if the file is a regular file.
Function: ISDIR (file) Returns true if the file is a directory.
Function: ISLINK (file) Returns true if the file is a link.
Command: CHMOD file, mode Change permissions of a file
' Make myfile available to anyone (read/write)
CHMOD "myfile.bas", 0o666
...
' Make myfile available to anyone (execute/read/write)
CHMOD "myfile.bas", 0o777

Function: EOF (fileN) Returns true if the file pointer is at end of the file. For COMx and SOCL VFS it returns true if the connection is broken.
Command: PRINT# fileN, [USING...] ... Write string to a file. The syntax is the same with the PRINT command. *, We can use 'USG' instead of 'USING'.
Command: LINPUT# [fileN,|;] var
Command: LINEINPUT# [#fileN,|;] var
Command: LINE-INPUT# [fileN,|;] var Reads a whole text line from file or console.
Function: INPUT (len [, fileN]) This function is similar to INPUT. Reads 'len' bytes from file or console (if fileN is omitted). This function is a low-level function. That means does not convert the data, and does not remove the spaces.
Command: INPUT# fileN; var1 [,delim] [, var2 [,delim]] ... Reads data from file
Function: BGETC (fileN) (Binary mode) Reads and returns a byte from file or device.
Command: BPUTC# fileN; byte (Binary mode) Writes a byte on file or device
Command: SEEK# fileN; pos Sets file position for the next read/write
Function: SEEK (fileN) Returns the current file position
Function: LOF (fileN) Returns the length of file in bytes. For other devices, it returns the number of available data.
Command: KILL "file" Deletes the specified file
Command: WRITE# fileN; var1 [, ...]
Command: READ# fileN; var1 [, ...] The READ/WRITE command set is used to store variables to a file as binary data. The common problem with INPUT/PRINT set is there are many conflicts with data.
PRINT #1; "Hello, world"
You have wrote only one string and you want read it in one variable, but this is impossible for INPUT command to understand it, because INPUT finds the separator comma, so it thinks there are two variables not one. So, now, you can store arrays, strings etc and what is you write is what you will read the next time. BTW its faster too. *, The parameters can be variables ONLY. *, Its very bad idea to mixed READ/WRITE commands with INPUT/PRINT commands in the same file.
Command: COPY "file", "newfile" Makes a copy of specified file to the 'newfile'
Command: RENAME "file", "newname" Renames the specified file
Command: MKDIR dir Create a directory. This does not working on PalmOS.
Command: CHDIR dir Changes the current working directory. This does not working on PalmOS.
Command: RMDIR dir Removes a directory. This does not working on PalmOS.
Command: DIRWALK directory [, wildcards] [USE ...] Walk through the directories. The user-defined function must returns zero to stop the process.
FUNC PRNF(x)
    ? x
    PRNF=TRUE
END
...
DIRWALK "." USE PRNF(x)
PalmOS, Not supported.
Function: FILES (wildcards) Returns an array with the filenames. If there is no files returns an empty array.
? FILES("*")
PalmOS, Returns only the user-files. *, To use file on MEMO or PDOC or any other virtual file system you must use FILES("VFSx:*")
PRINT FILES("MEMO:*")


[Prev] [Next]