asm, c, c++ are my all
-- Core In Computer
posts - 139,  comments - 123,  trackbacks - 0

检测文件存在的三种方法 - test if a File exist or not?

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. You can use 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.

posted on 2006-05-11 00:53 Jerry Cat 阅读(1237) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2006年5月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(7)

随笔档案

最新随笔

搜索

  •  

最新评论

阅读排行榜

评论排行榜