创建或打开文件(也可用于打开管道,油槽,硬件设备等):

HANDLE CreateFile(
LPCTSTR
lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
);
参数说明:
lpFileName:文件名
dwDesiredAccess对文件的打开模式,取值有:GENERIC_READ或者GENERIC_WRITE或者 0
dwShareMode: 文件的共享模式,FILE_SHARE_READ FILE_SHARE_WRITE FILE_SHARE_DELETE
lpSecurityAttributes: 指向 SECURITY_ATTRIBUTES结构的安全属性,可指定返回句柄是否可被继承
dwCreationDisposition Specifies which action to take on files that exist, and which action to take
when files do not exist. For more information about this parameter, see the
Remarks section. This parameter must be one of the following values.
CREATE_NEW Creates a new file. The function fails if the specified file already exists.
CREATE_ALWAYS Creates a new file. If the file exists, the function overwrites the file, clears the existing attributes, and combines the file attributes and flags specified by dwFlagsAndAttributes with FILE_ATTRIBUTE_ARCHIVE.
OPEN_EXISTING Opens the file. The function fails if the file does not exist.

For a discussion of why you should use the OPEN_EXISTING flag if you are using the CreateFile function for devices, see Remarks.

OPEN_ALWAYS Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW.
TRUNCATE_EXISTING Opens the file. Once opened, the file is truncated so that its size is zero bytes. The calling process must open the file with at least GENERIC_WRITE access. The function fails if the file does not exist.
 dwFlagsAndAttributes:文件属性取值有FILE_ATTRIBUTE_ARCHIVE,FILE_ATTRIBUTE_ENCRYPTED,FILE_ATTRIBUTE_HIDDEN
FILE_ATTRIBUTE_NORMAL,FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,FILE_ATTRIBUTE_OFFLINE,FILE_ATTRIBUTE_READONLY
FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_TEMPORARY 返回值:成功返回句柄,失败返回INVALID_HANDLE_VALUE 读文件:
BOOL ReadFile(
HANDLE
hFile, // handle to file
LPVOID lpBuffer, // data buffer
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // number of bytes read
LPOVERLAPPED lpOverlapped // overlapped buffer
); 返回值:失败返回FALSE成功赶回TRUE; 写文件:
BOOL WriteFile(
HANDLE
hFile, // handle to file
LPCVOID lpBuffer, // data buffer
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // number of bytes written
LPOVERLAPPED lpOverlapped // overlapped buffer
); 返回值:

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

复制文件:

BOOL CopyFile(
LPCTSTR
lpExistingFileName, // name of an existing file

                            LPCTSTR lpNewFileName, // name of new file

                            BOOL bFailIfExists // operation if file exists
);

返回值:成功返回非0,失败返回0

删除文件:
BOOL DeleteFile(
LPCTSTR
lpFileName // file name
);
只需提供文件名即可,成功返回非0,失败返回0 判断某一文件或目录是否存在:
BOOL PathFileExists(
LPCTSTR pszPath
);
pszPath
[in] Pointer to a null-terminated string of maximum length MAX_PATH that contains the full path of the object to verify.

返回值:

Returns TRUE if the file exists, or FALSE otherwise. Call GetLastError for extended
error information.

获取文件大小:

DWORD GetFileSize(
HANDLE
hFile, // handle to file
LPDWORD lpFileSizeHigh // high-order word of file size
);
返回文件低32位,高32位为第二个参数,第二个参数一般为NULL 获取文件名:
short GetFileTitle(
LPCTSTR
lpszFile, // path and file name
LPTSTR lpszTitle, // file name buffer
WORD cbBuf // length of buffer
);

Parameters

lpszFile
[in] Pointer to the name and location of a file.
lpszTitle
[out] Pointer to a buffer that receives the name of the file.
cbBuf
[in] Specifies the length, in TCHARs, of the buffer pointed to by the lpszTitle parameter. For the ANSI version of the function, this is in bytes; for the Unicode version, this is in characters.

Return Values

If the function succeeds, the return value is zero.

If the file name is invalid, the return value is unknown. If there is an error, the return value is a negative number

最新文章

  1. Ubuntu 16.10 安装byzanz截取动态效果图工具
  2. jQuery的ajax()、post()方法提交数组,参数[] 问题
  3. c++中new分配动态数组
  4. 【单点更新,区间查询,线段树】【HDU1166】【敌兵布阵】
  5. 用200行Python代码“换脸”
  6. 文《左右c++与java中国的垃圾问题的分析与解决》一bug分析
  7. VS XCOPY
  8. Vue.js 系列教程 ①
  9. 【干货】分享几个写 demo 的思路
  10. redhat 6.5安装ansible
  11. supervisor管理nginx
  12. Oracle学习DaySix(PL/SQL续)
  13. nginx的location、root、alias指令用法和区别
  14. C#转成时间格式
  15. jumperserver docker部署
  16. SQL到NoSQL概览性总结之一 数据库应用场景选型
  17. server.xml引入子文件配置(tomcat虚拟主机)[转]
  18. RobotFramework基本用法(二)
  19. Java新人拿到一台新的电脑需要装配什么
  20. 嵌入式C语言——提取时分秒

热门文章

  1. drop database出现1010
  2. 什么是存根类 Stub
  3. 关于Unity中的物理
  4. 左神算法基础班4_1&2实现二叉树的先序、中序、后序遍历,包括递归方式和非递归
  5. php 取某一日期的前一天
  6. Java 10的10个新特性,将彻底改变你写代码的方式!
  7. spring boot发简单文本邮件
  8. PyInstaller打包Python源文件为可执行程序exe
  9. marquee标签(跑马灯效果)
  10. CSS - 定位相关