RSS
热门关键字:  计算机有关资料  33252  mkv  word  MKV_NT
当前位置 : 主页>vc编程>平台/系统>列表

检测文件存在的三种方法

来源: 作者: 时间:2006-11-30 点击:

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

hFile=FindFirstFile(filename,&m_data)

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

Make sure you close the handle if the file is found.

FindClose(hFile);

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

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. 


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

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.

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册