Win32 API: File Management Functions

Comprehensive guide to handling files and directories on Windows.

Introduction

The Win32 API provides a robust set of functions for interacting with the file system on Windows. These functions allow applications to create, read, write, delete, and manage files and directories. Understanding these functions is crucial for developing any application that needs to persist data or interact with the underlying operating system's storage.

File Creation & Opening

These functions are used to create new files or open existing ones, specifying access rights and sharing modes.

CreateFile

Opens or creates a file or device.

CreateFile2

Creates or opens a handle to a specified file.

OpenFile

Opens an existing file or creates a new file.

File Reading & Writing

Functions for reading data from and writing data to files.

ReadFile

Reads data from a file or input buffer.

WriteFile

Writes data to a file or output buffer.

ReadFileEx

Reads data from a file or device, using overlapped I/O.

WriteFileEx

Writes data to a file or device, using overlapped I/O.

File Positioning

Control the current read/write position within a file.

SetFilePointer

Moves the file pointer of the specified file to a location.

SetFilePointerEx

Moves the file pointer of the specified file to a location.

GetFileSizeEx

Retrieves the size of the specified file.

File Closing

Release resources associated with an open file handle.

CloseHandle

Closes an open object handle.

File Information

Retrieve metadata and attributes about files.

GetFileAttributes

Retrieves the attributes of a file or directory.

GetFileAttributesEx

Retrieves file attributes for a specified file or directory.

FindFirstFile

Searches a directory for a file or subdirectory that matches a specified format.

FindNextFile

Searches a directory for a file or subdirectory that matches a specified format.

FindClose

Closes the search handle and releases all resources associated with the find operation.

Directory Management

Operations related to creating, deleting, and manipulating directories.

CreateDirectory

Creates a new directory.

CreateDirectoryEx

Creates a new directory with specified attributes and security descriptor.

RemoveDirectory

Deletes an existing empty directory.

GetCurrentDirectory

Retrieves the current directory for the current process.

SetCurrentDirectory

Changes the current directory for the current process.

File Attributes

Functions to set and modify file attributes.

SetFileAttributes

Sets the attributes of a file or directory.

SetFileAttributesEx

Sets the attributes for a specified file or directory.

Other Operations

Additional useful file system operations.

CopyFile

Copies an existing file to a new location.

MoveFile

Moves an existing file or directory from one location to another.

DeleteFile

Deletes an existing file.

CreateHardLink

Creates a hard link to an existing file.

CreateSymbolicLink

Creates a symbolic link.