Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Small Basic: Reference Documentation > File
http://smallbasic.com/img/object_32.png
The File object provides methods to access, read and write information from and to a file on disk. Using this object, it is possible to save and open settings across multiple sessions of your program.
File.LastError
Gets or sets the last encountered file operation based error message. This property is useful for finding out when some method fails to execute.
http://smallbasic.com/img/method_16.png ReadContents
File.ReadContents(filePath)
Opens a file and reads the entire file's contents. This method will be fast for small files that are less than an MB in size, but will start to slow down and will be noticeable for files greater than 10MB.
The full path of the file to read. An example of a full path will be c:\temp\settings.data.
The entire contents of the file.
http://smallbasic.com/img/method_16.png WriteContents
File.WriteContents(filePath, contents)
Opens a file and writes the specified contents into it, replacing the original contents with the new content.
The full path of the file to write to. An example of a full path will be c:\temp\settings.data.
The contents to write into the specified file.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
File.ReadLine(filePath, lineNumber)
Opens the specified file and reads the contents at the specified line number.
The full path of the file to read from. An example of a full path will be c:\temp\settings.data.
The line number of the text to be read.
The text at the specified line of the specified file.
http://smallbasic.com/img/method_16.png WriteLine
File.WriteLine(filePath, lineNumber, contents)
Opens the specified file and write the contents at the specified line number. This operation will overwrite any existing content at the specified line.
The full path of the file to read from. An example of a full path will be c:\temp\settings.data.
The line number of the text to write.
The contents to write at the specified line of the specified file.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png InsertLine
File.InsertLine(filePath, lineNumber, contents)
Opens the specified file and inserts the contents at the specified line number. This operation will not overwrite any existing content at the specifid line.
The full path of the file to read from. An example of a full path will be c:\temp\settings.data.
The line number of the text to insert.
The contents to insert into the file.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png AppendContents
File.AppendContents(filePath, contents)
Opens the specified file and appends the contents to the end of the file.
The full path of the file to read from. An example of a full path will be c:\temp\settings.data.
The contents to append to the end of the file.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
File.CopyFile(sourceFilePath, destinationFilePath)
Copies the specified source file to the destination file path. If the destination points to a location that doesn't exist, the method will attempt to create it automatically. Existing files will be overwritten. It is always best to check if the destination file exists if you don't want to overwrite existing files.
The full path of the file that needs to be copied. An example of a full path will be c:\temp\settings.data.
The destination location or the file path.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png DeleteFile
File.DeleteFile(filePath)
Deletes the specified file.
The destination location or the file path. An example of a full path will be c:\temp\settings.data.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png CreateDirectory
File.CreateDirectory(directoryPath)
Creates the specified directory.
The full path of the directory to be created.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png DeleteDirectory
File.DeleteDirectory(directoryPath)
Deletes the specified directory.
The full path of the directory to be deleted.
If the operation was successful, this will return "SUCCESS". Otherwise, it will return "FAILED".
File.GetFiles(directoryPath)
Gets the path of all the files in the specified directory path.
The directory to look for files.
If the operation was successful, this will return the files as an array. Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png GetDirectories
File.GetDirectories(directoryPath)
Gets the path of all the directories in the specified directory path.
The directory to look for subdirectories.
If the operation was successful, this will return the list of directories as an array. Otherwise, it will return "FAILED".
http://smallbasic.com/img/method_16.png GetTemporaryFilePath
File.GetTemporaryFilePath()
Creates a new temporary file in a temporary directory and returns the full file path.
The full file path of the temporary file.
http://smallbasic.com/img/method_16.png GetSettingsFilePath
File.GetSettingsFilePath()
Gets the full path of the settings file for this program. The settings file name is based on the program's name and is present in the same location as the program.
The full path of the settings file specific for this program.