APIS for Windows File Operations (createfile Series)

Source: Internet
Author: User

In VC, most file operations use the API functions provided by the system, but some functions are not very familiar to us. The following describes some file operation API functions:

General file operation API

Createfile
Open a file
To read and write a file, you must first obtain the file handle. This function can be used to obtain the file handle, which is the door to the file world.

Readfile
Read byte information from a file.
After opening the file and obtaining the file handle, you can use this function to read data.

Writefile
Write byte information to the file.
You can also pass the file handle to this function to Write File data.

Closehandle
Close the file handle.
After opening the door, remember to close it.

Getfiletime
Obtain the file time.
There are three file time options: creation time, last access time, and last write time.
This function also requires the file handle as the entry parameter.

Getfilesize
Obtain the file size.
Because the file size can be as high as several GB (1 GB requires 30 bits), a 32-bit dubyte type cannot be accurately expressed, so the return code is 32 bits, there is also an exit parameter that can output a 32-bit high.
This function also requires the file handle as the entry parameter.

Getfileattributes
Obtain file attributes.
You can obtain attributes such as archive, read-only, system, and hide.
This function uses only one file path as the parameter.

Setfileattributes
Set file properties.
Can be obtained, and should also be set.
You can set attributes such as archive, read-only, system, and hide.
This function uses only one file path as the parameter.

Getfileinformationbyhandle
Get all file information
This function can obtain the information that all functions above can obtain, such as the size and attribute. It also contains information that cannot be obtained from other places, such as file volume tag, index, and link information.
This function requires the file handle as the entry parameter.

Getfullpathname
Obtain the file path. This function obtains the complete path name of the file.
Note that the result is correct only when the file is in the current directory. If you want to get the real path. Use the getmodulefilename function.

Copyfile
Copy a file
Note: Only files can be copied, but directories cannot be copied.

Movefileex
Move files
You can move files or directories, but not across drive letters. (You can set a move flag in Windows to span the drive letter)

Deletefile
Delete an object

Gettemppath
Obtain the Windows temporary directory path

Gettempfilename
Create a unique temporary file under the Windows temporary directory path

Setfilepoint
Move the file pointer.
This function is used to perform advanced read/write operations on files.

File Locking and unlocking

Lockfile
Unlockfile
Lockfileex
Unlockfileex

The above four functions are used to lock and unlock the file. In this way, asynchronous file operations can be implemented. You can perform operations on different parts of the file at the same time.

File compression and decompression

Lzopenfile
Open the compressed file to read

Lzseek
Find a location in the compressed file

Lzread
Read a compressed file

Lzclose
Close a compressed file

Lzcopy
Copy the compressed file and expand it during processing

Getexpandedname
Returns the file name from the compressed file.

The above six functions are a small extension library in the 32-bit API, and the functions in the File compression extension library. You can use the compress command to Create File compression.

File Kernel Object

The 32-bit API provides a feature called a file image that allows you to map files directly to the virtual memory space of an application. This technology can be used to simplify and accelerate file access.

Createfilemapping
Create and name ing

Mapviewoffile
Load file ing like memory

Unmapviewoffile
Release the view and write the changes back to the file

Flushviewoffile
Refresh view changes to disk

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wwwwly/archive/2009/06/08/4250895.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.