检测文件存在的三种方法

1. 强大, 可配合FindNextFile(), FindClose(), 其中后者是必备.
WIN32_FIND_DATA m_data;
HANDLE hFile; 字串3

hFile=FindFirstFile(filename,&m_data) 字串8

if(hFile==INVALID_HANDLE_VALUE) //file not found

字串1

 

Make sure you close the handle if the file is found. 字串3

FindClose(hFile); 字串3

2. 你可以使用 SHGetFileInfo()
The prototype of the function is as follows: 字串7

DWORD_PTR SHGetFileInfo(
LPCTSTR pszPath,
DWORD dwFileAttributes,
SHFILEINFO *psfi,
UINT cbFileInfo,
UINT uFlags
);
备注:
Minimum DLL Version shell32.dll version 4.0 or later
Header  shellapi.h
Import  library shell32.lib (若是ClassWizard建的无论是SDK还是MFC都会自包括)
Minimum operating systems Windows NT 4.0, Windows 95
Unicode Implemented as ANSI and Unicode versions.  字串2


3. 简洁的 PathFileExists()
BOOL PathFileExists(
    LPCTSTR lpszPath
    ); 字串3

Purpose: Determines if a file exists.
Remark:  #include "Shlwapi.h"

Minimum DLL Version shlwapi.dll version 4.71 or later
Header  shlwapi.h
Import  library shlwapi.lib
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Unicode Implemented as ANSI and Unicode versions. 字串 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值