File System API Reference
This section provides detailed documentation for the Windows File System APIs, enabling developers to interact with files, directories, volumes, and other file system objects programmatically.
Core File Operations
These functions allow you to perform fundamental operations on files and directories.
File Information and Attributes
Retrieve and set various properties of files and directories.
Advanced File System Features
Explore more sophisticated file system functionalities.
CreateFile
Syntax:
HANDLE CreateFile(
_In LPCTSTR lpFileName,
_In DWORD dwDesiredAccess,
_In DWORD dwShareMode,
_In_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_In DWORD dwCreationDisposition,
_In DWORD dwFlagsAndAttributes,
_In_opt HANDLE hTemplateFile
);
Description: Creates or opens a file or I/O device. It returns a handle to the specified device, which can be used for subsequent I/O operations.
Parameters:
lpFileName
: The name of the file or device to be created or opened.dwDesiredAccess
: The requested access to the file or device.dwShareMode
: A bitmask of flags that specify how the file or device should be shared.lpSecurityAttributes
: A pointer to aSECURITY_ATTRIBUTES
structure that specifies the security attributes of the file or device.dwCreationDisposition
: An action to take if the file does or does not exist.dwFlagsAndAttributes
: The file attributes and extended attributes for the file or directory.hTemplateFile
: A handle to a template file with the attributes and extended attributes that are to be copied to the specified file.
Return Value: If the function succeeds, the return value is an open handle to the specified file or device. If the function fails, the return value is INVALID_HANDLE_VALUE
.
ReadFile
Syntax:
BOOL ReadFile(
_In HANDLE hFile,
_Out LPVOID lpBuffer,
_In DWORD nNumberOfBytesToRead,
_Out_opt LPDWORD lpNumberOfBytesRead,
_Inout_opt LPOVERLAPPED lpOverlapped
);
Description: Reads data from a file or input buffer into an array, starting at a specified offset. This function is the general-purpose file reading function.
Parameters:
hFile
: A handle to the file or device (CreateFile
) that is to be read.lpBuffer
: A pointer to the buffer that receives the data read from the file.nNumberOfBytesToRead
: The maximum number of bytes to be read.lpNumberOfBytesRead
: A pointer to a variable that receives the number of bytes actually read.lpOverlapped
: A pointer to anOVERLAPPED
structure.
Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
WriteFile
Syntax:
BOOL WriteFile(
_In HANDLE hFile,
_In_const LPVOID lpBuffer,
_In DWORD nNumberOfBytesToWrite,
_Out_opt LPDWORD lpNumberOfBytesWritten,
_Inout_opt LPOVERLAPPED lpOverlapped
);
Description: Writes data to a file or I/O device. It starts writing data to the file at the position indicated by the file-pointer.
Parameters:
hFile
: A handle to the file or device (CreateFile
) that is to be written to.lpBuffer
: A pointer to the buffer containing the data to be written to the file.nNumberOfBytesToWrite
: The number of bytes to be written to the file.lpNumberOfBytesWritten
: A pointer to a variable that receives the number of bytes actually written.lpOverlapped
: A pointer to anOVERLAPPED
structure.
Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.