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)

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_ReadFile(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_ReadTextFile(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_WriteFile(Handle.l, Filename.s)

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_CloseFile([Handle.l])

Close the file [it can't be used anymore].
PureFILE_Use(Handle.l)

Change the current used file.

PureFILE_IsFile(Handle.l)

Tests if the given handle is a valid file handle.

Returns #TRUE or #FALSE.
PureFILE_Eof([Handle.l])

Returns #TRUE if the end of the file is reached, else returns #FALSE.
PureFILE_NotEof([Handle.l])

Returns #FALSE if the end of the file is reached, else returns #TRUE.
PureFILE_Lof([Handle.l])

Returns the length of the opened file.
PureFILE_FileSeek([Handle.l], NewPosition.l)

Change the pointer position (in bytes) inside the file.
PureFILE_CountLines([Handle.l])

Count the lines in a text file opened with PureFILE_ReadTextFile().
PureFILE_ReadByte([Handle.l])

Read one byte from the opened file.
PureFILE_ReadWord([Handle.l])

Read one word from the opened file.
PureFILE_ReadLong([Handle.l])

Read one long from the opened file.
PureFILE_ReadString([Handle.l])

Read one string from the opened file (read a string in the opened file until an EOL character is found).
PureFILE_ReadData([Handle.l,] *Buffer, BufferLen.l)

Read file content into the memory buffer [returns the number of bytes read].
PureFILE_WriteByte([Handle.l,] ByteToWrite.b)

Write one byte to the opened file.
PureFILE_WriteWord([Handle.l,] WordToWrite.w)

Write one word to the opened file.
PureFILE_WriteLong([Handle.l,] LongToWrite.l)

Write one long to the opened file.
PureFILE_WriteString([Handle.l,] StringToWrite.s)

Write one string to the opened file.
PureFILE_WriteStringN([Handle.l,] StringToWrite.s)

Write one text line to the opened file (write a string and add the EOL character).

PureFILE_WriteData([Handle.l,] *Buffer, BufferLen.l)

Write the content of the memory buffer in the file [returns the number of written bytes].
PureFILE_FindLongInFile(Filename.s, Long.l, [StartPosition.l])

Load file in memory and search for long [returns offset if found].
PureFILE_FindStringInFile(Filename.s, String.s, [StartPosition.l])

Load file in memory and search for string [returns offset if found].
PureFILE_SetBuffer(BufferSize.l)

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_GetAttributes(Filename.s)

Retrieves the file attributes.


File attributes :
#FILE_ATTRIBUTE_ARCHIVE
#FILE_ATTRIBUTE_HIDDEN
#FILE_ATTRIBUTE_READONLY
#FILE_ATTRIBUTE_SYSTEM
PureFILE_SetAttributes(Filename.s, Attributes.l)

Set the file attributes.

File attributes :
#FILE_ATTRIBUTE_ARCHIVE
#FILE_ATTRIBUTE_HIDDEN
#FILE_ATTRIBUTE_READONLY
#FILE_ATTRIBUTE_SYSTEM
PureFILE_AddAttributes(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_SYSTEM
PureFILE_RemoveAttributes(Filename.s, Attributes.l)

Remove attribute(s) from the current file attributes.

File attributes :
#FILE_ATTRIBUTE_ARCHIVE
#FILE_ATTRIBUTE_HIDDEN
#FILE_ATTRIBUTE_READONLY
#FILE_ATTRIBUTE_SYSTEM
PureFILE_GetDate(Filename.s)

Retrieves file date [Purebasic date format].
PureFILE_SetDate(Filename.s, NewDate.l)

Set new file date [Purebasic date format].
PureFILE_CreateDirectory(DirPath.s)

Creates all the directories in the specified DirPath.

Returns #FALSE if failed.
PureFILE_CreateLink(LinkFileName.s, FileLinkedTo.s, Arguments.s, Description.s, WorkingDirectory.s, ShowCommand.l, HotKey.l, IconFile.s, IconIndexInFile.l)

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_GetCurrentDirectory()

Retrieves the current directory for the current process.
PureFILE_GetExePath()

Retrieves the full path for the executable file.
PureFILE_GetFullExePath()

Retrieves the full path and filename for the executable file.

PureFILE_GetTempDir()

Retrieves the path of the directory designated for temporary files.
PureFILE_GetJaPBeFolder()

Retrieves jaPBe folder.

Returns an empty string if not installed.
PureFILE_GetPurebasicFolder()

Retrieves Purebasic folder.

Returns an empty string if not installed.
PureFILE_GetDriveFromUNCPath(UNCPath.s)

Retrieves the name of the local device associated with the network resource.

Returns an empty string if none.
PureFILE_GetUNCPathFromDrive(DriveLetter.s)

Retrieves the name of the network resource associated with a local device.

Returns the drive letter if none.
PureFILE_GetDriveSerial(PhysicalDrive.l)

Retrieves the physical drive serial (thanks Rings).

Returns an empty string if failed.
PureFILE_GetPCName()

Retrieves PC name.

If network is present it's the hostname, else it's the computer name.
PureFILE_GetUserName()

Retrieves the user name.

It's the name of the user currently logged onto the system.
PureFILE_MatchWildcard(Filename.s, Wildcard.s)

Test if Filename matches with Wildcard [returns #TRUE or #FALSE.
PureFILE_ResizeFile(Filename.s, NewLength.l)

Resize file to new length.

Returns NewLength is succeed, #FALSE if failed.
PureFILE_SearchForFile(Directory.s, Filename.s)

Search for Filename in Directory recursively.

Returns file path if found, empty string if not.
PureFILE_GetFilePartWithoutExtension(Filename.s)

Get the file part of a full pathname but without the extension.
PureFILE_GetDiskFreeSpace(Drive.s)

Retrieves the amount of free space available (in Mb) on a disk volume.

Returns -1 if failed.
PureFILE_GetFreeRAM()

Retrieves the amount of free physical memory bytes.
PureFILE_GetTotalRAM()

Retrieves the amount of bytes of physical memory.