PureFILE library
Overview
This user library offers WinAPI based buffered file functions, usually faster than the genuine Purebasic 3.94 ones, but with a similar syntax.
PB 4.xx version.
Purebasic 4+ now also has buffered file functions, so this library is only released for old code compatibility.
Functions
PureFILE_CreateFile(Handle.l, Filename.s)PureFILE_ReadFile(Handle.l, Filename.s)Creates a file for writing. If the file already exists, it is replaced by an empty one. Handle is a number from 1 to 30 or #PB_Any. If #PB_Any is used as handle, the new file handle will be returned as result. Returns the actual file handle, or #NULL if failed.PureFILE_ReadTextFile(Handle.l, Filename.s)Opens an existing file for reading Handle is a number from 1 to 30 or #PB_Any. If #PB_Any is used as handle, the new file handle will be returned as result. Returns the actual file handle, or #NULL if failed.PureFILE_WriteFile(Handle.l, Filename.s)Opens an existing text file for reading. Use this function for fast text reading with PureFILE_ReadString(). Warning : the whole file is loaded into memory. Handle is a number from 1 to 30 or #PB_Any. If #PB_Any is used as handle, the new file handle will be returned as result. Returns the actual file handle, or #NULL if failed.PureFILE_CloseFile([Handle.l])Opens an existing a file for writing. Handle is a number from 1 to 30 or #PB_Any. If #PB_Any is used as handle, the new file handle will be returned as result. Returns the actual file handle, or #NULL if failed.PureFILE_Use(Handle.l)Close the file [it can't be used anymore].PureFILE_IsFile(Handle.l)Change the current used file.PureFILE_Eof([Handle.l])Tests if the given handle is a valid file handle. Returns #TRUE or #FALSE.PureFILE_NotEof([Handle.l])Returns #TRUE if the end of the file is reached, else returns #FALSE.PureFILE_Lof([Handle.l])Returns #FALSE if the end of the file is reached, else returns #TRUE.PureFILE_FileSeek([Handle.l], NewPosition.l)Returns the length of the opened file.PureFILE_CountLines([Handle.l])Change the pointer position (in bytes) inside the file.PureFILE_ReadByte([Handle.l])Count the lines in a text file opened with PureFILE_ReadTextFile().PureFILE_ReadWord([Handle.l])Read one byte from the opened file.PureFILE_ReadLong([Handle.l])Read one word from the opened file.PureFILE_ReadString([Handle.l])Read one long from the opened file.PureFILE_ReadData([Handle.l,] *Buffer, BufferLen.l)Read one string from the opened file (read a string in the opened file until an EOL character is found).PureFILE_WriteByte([Handle.l,] ByteToWrite.b)Read file content into the memory buffer [returns the number of bytes read].PureFILE_WriteWord([Handle.l,] WordToWrite.w)Write one byte to the opened file.PureFILE_WriteLong([Handle.l,] LongToWrite.l)Write one word to the opened file.PureFILE_WriteString([Handle.l,] StringToWrite.s)Write one long to the opened file.PureFILE_WriteStringN([Handle.l,] StringToWrite.s)Write one string to the opened file.PureFILE_WriteData([Handle.l,] *Buffer, BufferLen.l)Write one text line to the opened file (write a string and add the EOL character).PureFILE_FindLongInFile(Filename.s, Long.l, [StartPosition.l])Write the content of the memory buffer in the file [returns the number of written bytes].PureFILE_FindStringInFile(Filename.s, String.s, [StartPosition.l])Load file in memory and search for long [returns offset if found].PureFILE_SetBuffer(BufferSize.l)Load file in memory and search for string [returns offset if found].PureFILE_GetAttributes(Filename.s)Set the PureFILE read buffer size [default size is 32768 bytes]. If BufferSize = #PB_Any, the buffer size will be the opened file length.PureFILE_SetAttributes(Filename.s, Attributes.l)Retrieves the file attributes. File attributes : #FILE_ATTRIBUTE_ARCHIVE #FILE_ATTRIBUTE_HIDDEN #FILE_ATTRIBUTE_READONLY #FILE_ATTRIBUTE_SYSTEMPureFILE_AddAttributes(Filename.s, Attributes.l)Set the file attributes. File attributes : #FILE_ATTRIBUTE_ARCHIVE #FILE_ATTRIBUTE_HIDDEN #FILE_ATTRIBUTE_READONLY #FILE_ATTRIBUTE_SYSTEMPureFILE_RemoveAttributes(Filename.s, Attributes.l)Adds attribute(s) to the current file attributes. File attributes : #FILE_ATTRIBUTE_ARCHIVE #FILE_ATTRIBUTE_HIDDEN #FILE_ATTRIBUTE_READONLY #FILE_ATTRIBUTE_SYSTEMPureFILE_GetDate(Filename.s)Remove attribute(s) from the current file attributes. File attributes : #FILE_ATTRIBUTE_ARCHIVE #FILE_ATTRIBUTE_HIDDEN #FILE_ATTRIBUTE_READONLY #FILE_ATTRIBUTE_SYSTEMPureFILE_SetDate(Filename.s, NewDate.l)Retrieves file date [Purebasic date format].PureFILE_CreateDirectory(DirPath.s)Set new file date [Purebasic date format].PureFILE_CreateLink(LinkFileName.s, FileLinkedTo.s, Arguments.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndexInFile.l)Creates all the directories in the specified DirPath. Returns #FALSE if failed.PureFILE_GetCurrentDirectory()Create a link (thanks Danilo). LinkFileName : Link filename (*.lnk) ; FileLinkedTo : File linked to ; Arguments : Arguments for the target ; WorkingDirectory : Working Directory ; Description : Description ( also used as tooltip for the link ) ; ShowCommand : Show command (SW_SHOWNORMAL = Default ) ; HotKey : The virtual key code in the low-order byte, and modifier flags are in the high-order byte ; Icon File / Index : Icon used for the link.PureFILE_GetExePath()Retrieves the current directory for the current process.PureFILE_GetFullExePath()Retrieves the full path for the executable file.PureFILE_GetTempDir()Retrieves the full path and filename for the executable file.PureFILE_GetJaPBeFolder()Retrieves the path of the directory designated for temporary files.PureFILE_GetPurebasicFolder()Retrieves jaPBe folder. Returns an empty string if not installed.PureFILE_GetDriveFromUNCPath(UNCPath.s)Retrieves Purebasic folder. Returns an empty string if not installed.PureFILE_GetUNCPathFromDrive(DriveLetter.s)Retrieves the name of the local device associated with the network resource. Returns an empty string if none.PureFILE_GetDriveSerial(PhysicalDrive.l)Retrieves the name of the network resource associated with a local device. Returns the drive letter if none.PureFILE_GetPCName()Retrieves the physical drive serial (thanks Rings). Returns an empty string if failed.PureFILE_GetUserName()Retrieves PC name. If network is present it's the hostname, else it's the computer name.PureFILE_MatchWildcard(Filename.s, Wildcard.s)Retrieves the user name. It's the name of the user currently logged onto the system.PureFILE_ResizeFile(Filename.s, NewLength.l)Test if Filename matches with Wildcard [returns #TRUE or #FALSE.PureFILE_SearchForFile(Directory.s, Filename.s)Resize file to new length. Returns NewLength is succeed, #FALSE if failed.PureFILE_GetFilePartWithoutExtension(Filename.s)Search for Filename in Directory recursively. Returns file path if found, empty string if not.PureFILE_GetDiskFreeSpace(Drive.s)Get the file part of a full pathname but without the extension.PureFILE_GetFreeRAM()Retrieves the amount of free space available (in Mb) on a disk volume. Returns -1 if failed.PureFILE_GetTotalRAM()Retrieves the amount of free physical memory bytes.Retrieves the amount of bytes of physical memory.