VC检测文件存在的几种方法
来源:互联网 发布:索尼playmemories软件 编辑:程序博客网 时间:2024/04/28 17:25
方法一:FindFirstFile
1
WIN32_FIND_DATA m_data;
2
HANDLE
hFile;
3
hFile=FindFirstFile(filename,&m_data)
4
if
(hFile==INVALID_HANDLE_VALUE)
//file not found
5
//Make sure you close the handle if the file is found.
6
FindClose(hFile);
方法二:SHGetFileInfo
函数原型如下:
1
DWORD_PTR
SHGetFileInfo(
2
LPCTSTR
pszPath,
3
DWORD
dwFileAttributes,
4
SHFILEINFO *psfi,
5
UINT
cbFileInfo,
6
UINT
uFlags
7
);
方法三:PathFileExists
//请注意:为了使用API函数PathFileExists(),需要加入shlqapi头文件和lib
1
#include "Shlwapi.h"
2
#pragma comment(lib,"shlwapi.lib")
3
if
(PathFileExists(str))
4
{
5
CString strTemp;
6
strTemp.Format(
"%s已存在!"
,str);
7
AfxMessageBox(strTemp);
8
return
;
9
}
方法四:标准c库函数_access
From MSDN
01
/* ACCESS.C: This example uses _access to check the
02
* file named "ACCESS.C" to see if it exists and if
03
* writing is allowed.
04
*/
05
06
#include <io.h>
07
#include <stdio.h>
08
#include <stdlib.h>
09
10
void
main(
void
)
11
{
12
/* Check for existence */
13
if
( (_access(
"ACCESS.C"
, 0 )) != -1 )
14
{
15
printf
(
"File ACCESS.C exists/n"
);
16
/* Check for write permission */
17
if
( (_access(
"ACCESS.C"
, 2 )) != -1 )
18
printf
(
"File ACCESS.C has write permission/n"
);
19
}
20
}
- VC检测文件存在的几种方法
- VC 判断文件是否存在的几种方法
- VC 判断文件是否存在的几种方法
- VC 判断文件是否存在的几种方法
- 检测文件存在的四种方法
- php 检测文件是否存在的几种方式
- VC 检测内存泄露的几种方法
- 检测一个文件是否存在的方法
- 判断文件是否存在的几种方法
- PHP判断远程文件是否存在的几种方法
- PHP判断远程文件是否存在的几种方法
- VC++ 使用MSComm控件检测串口是否存在的方法
- 在VC中加载LIB文件的几种方法
- NET检测文件和文件夹是否存在的方法
- VC下判断文件是否存在的方法
- VC下判断文件是否存在的方法
- VC判断文件目录是否存在的众多方法
- 利用JS判断图片,文件是否存在的几种方法
- mac下php(fastcgi)使用
- 重建图标存
- 分享SQL海量数据查询优化性能的总结
- 重新注册IIS
- C++中使用内存映射文件处理大文件
- VC检测文件存在的几种方法
- 数据库优化查询计划的方法
- 医学图像数据库
- jxl 判断excel 单元格是否为日期
- WIN7重装系统后的引导修复
- 页目录和页表结构
- 关于注册表的一些操作,C#
- jQuery 选择器
- C的0长数组