====== File ====== ===== Description ===== tFile.h Provides three primary functions. * The first function is that of a "file descriptor," or an abstracted way to identify a file. * The second function is "file resolution"; given an abstract relative or absolute path, the File class will properly resolve a path to a native file name. * Finally, the File class allows for various methods to test the properties of the file represented by the class. ===== Construction ===== tFile::tFile(const char *filename = "."); ^ parameter ^ type ^ description ^ | filename | const char * | relative or absolute file or directory name | tFile::tFile(const tFile &newfile); ^ parameter ^ type ^ description ^ | newfile | const tFile & | copy constructor | Construction should be fairly straightforward; if no parameter is provided for construction, the current directory will be the result. The File class can be considered immutable, with the exception that you may use the copy constructor to essentially "overwrite" what is already there. Some might say that breaks immutability, however, none of the methods of File modify the descriptor within the class otherwise. ===== Casting ===== inline operator const char*() const; inline operator char*() const; These operators allow you to cast a File as a **%%char*%%**, or **%%const char*%%**, needed for fopen or the like. These pointers are automatic as they're provided internally by a std::string, so do not manually **%%delete[]%%** them. ===== Methods ===== bool exists() const; ^ return type ^ description ^ | bool | returns **true** if the descriptor is a file, and already exists | void getParentDir(tFile &newfile) const; ^ parameter ^ type ^ description ^ | newfile | tFile & | File descriptor to hold the "parent directory" of this; this does not necessarily have to exist | bool isDirectory() const; ^ return type ^ description ^ | bool | returns **true** if this descriptor is a directory, and already exists | void list(vector &newlist) const; ^ parameter ^ type ^ description ^ | newlist | vector | clears the vector and fills it with a list of all files for a given directory; the vector will not contain "." or ".." | bool mkdir() const; ^ return type ^ description ^ | bool | returns **true** if a directory was able to be created based on this descriptor; this method will attempt to recursively create the parents required for the command to work. | bool remove() const; ^ return type ^ description ^ | bool | returns **true** if this file/directory existed, and was able to be removed(or deleted.) | bool rename(const tFile &newfile) const; ^ parameter ^ type ^ description ^ | newfile | const tFile & | file descriptor to rename the file pointed at by this file descriptor to | ^ return type ^ description ^ | bool | returns **true** if this file/directory existed, and was successfully renamed to newfile | tUInt32 size() const; ^ return type ^ description ^ | tUInt32 | returns the size of the file, in bytes, if it exists; zero otherwise. | ===== Notes ===== * This class requires [[filepeer]] to function properly. * As mentioned previously, **do not delete** the pointers returned by char* and const char* casts