System/File I/O API Reference

This section details the core Windows API functions for managing files, directories, and other input/output operations at the system level.

Creating and Opening Files

These functions are used to create new files or open existing ones for reading, writing, or both.

CreateFile

HANDLE CreateFile( [in] LPCTSTR lpFileName, [in] DWORD dwDesiredAccess, [in] DWORD dwShareMode, [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes, [in] DWORD dwCreationDisposition, [in] DWORD dwFlagsAndAttributes, [in, optional] HANDLE hTemplateFile );

Creates or opens a handle to a specified file or device. It is the primary function for file access.

CreateFileTransacted

HANDLE CreateFileTransacted( [in] LPCTSTR lpFileName, [in] DWORD dwDesiredAccess, [in] DWORD dwShareMode, [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes, [in] DWORD dwCreationDisposition, [in] DWORD dwFlagsAndAttributes, [in, optional] HANDLE hTemplateFile, [in] HANDLE hTransaction, [in, optional] PUSHORT pusMiniVersionMinor, [in, optional] PVOID pvReserved );

Creates or opens a file handle in a transaction.

Reading and Writing Files

Once a file is opened, these functions are used to transfer data between memory and the file.

ReadFile

BOOL ReadFile( [in] HANDLE hFile, [out] LPVOID lpBuffer, [in] DWORD nNumberOfBytesToRead, [out, optional] LPDWORD lpNumberOfBytesRead, [in, out, optional] LPOVERLAPPED lpOverlapped );

Reads data from a file or overlapping I/O buffer.

WriteFile

BOOL WriteFile( [in] HANDLE hFile, [in] LPCVOID lpBuffer, [in] DWORD nNumberOfBytesToWrite, [out, optional] LPDWORD lpNumberOfBytesWritten, [in, out, optional] LPOVERLAPPED lpOverlapped );

Writes data to a file or overlapping I/O buffer.

ReadFileEx

BOOL ReadFileEx( [in] HANDLE hFile, [out] LPVOID lpBuffer, [in] DWORD nNumberOfBytesToRead, [in, out] LPOVERLAPPED lpOverlapped, [in, optional] LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine );

Reads data from a file and calls a completion routine when the operation is complete.

WriteFileEx

BOOL WriteFileEx( [in] HANDLE hFile, [in] LPCVOID lpBuffer, [in] DWORD nNumberOfBytesToWrite, [in, out] LPOVERLAPPED lpOverlapped, [in, optional] LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine );

Writes data to a file and calls a completion routine when the operation is complete.

Closing Files

Releases the handle to a file and cleans up associated resources.

CloseHandle

BOOL CloseHandle( [in] HANDLE hObject );

Closes an open object handle. This includes file handles, process handles, thread handles, etc.

File Attributes and Information

Functions to retrieve, set, or query information about files and their attributes.

GetFileAttributes

DWORD GetFileAttributes( [in] LPCTSTR lpFileName );

Retrieves attributes for a specified file or directory.

SetFileAttributes

BOOL SetFileAttributes( [in] LPCTSTR lpFileName, [in] DWORD dwFileAttributes );

Sets the attributes for a file or directory.

GetFileSizeEx

BOOL GetFileSizeEx( [in] HANDLE hFile, [out] PLARGE_INTEGER lpFileSize );

Retrieves the size of the specified file.

Directory Management

APIs for creating, enumerating, and managing directories.

CreateDirectory

BOOL CreateDirectory( [in] LPCTSTR lpPathName, [in, optional] LPSECURITY_ATTRIBUTES lpAttribute );

Creates a new directory. If the directory already exists, the function succeeds and returns nonzero.

RemoveDirectory

BOOL RemoveDirectory( [in] LPCTSTR lpPathName );

Deletes an existing empty directory.

FindFirstFile

HANDLE FindFirstFile( [in] LPCTSTR lpFindFileData, [out] LPWIN32_FIND_DATA lpFindFileData );

Begins the process of searching for files that match a specific pattern.