稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

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

1.
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
);


3.
PathFileExists

4. 加一个标准c库函数

Example

/* ACCESS.C: This example uses _access to check the
 * file named "ACCESS.C" to see if it exists and if
 * writing is allowed.
 */

#include  <io.h>
#include  <stdio.h>
#include  <stdlib.h>

void main( void )
{
   /* Check for existence */
   if( (_access( "ACCESS.C", 0 )) != -1 )
   {
      printf( "File ACCESS.C exists\n" );
      /* Check for write permission */
      if( (_access( "ACCESS.C", 2 )) != -1 )
         printf( "File ACCESS.C has write permission\n" );
   }
}

posted on 2006-05-10 14:14 AlanTop 阅读(4056) 评论(4)  编辑 收藏 引用 所属分类: C++

评论

# re: 检测文件存在的三种方法。test if a File exist or not?  回复  更多评论   

竟然都没有一个是用标准API的?
access
2006-05-11 11:56 | 音乐虫子

# re: 检测文件存在的三种方法。test if a File exist or not?  回复  更多评论   

正想说呢,结果被楼上先说了。:)

看来M$的宣传到位啊。这么多难用的方法(最后一个还算不错),楼主都知道了,就是不知道标准C库的方法。
2006-05-11 13:25 | 沐枫

# re: 检测文件存在的第一种方法种方法。test if a File exist or not?  回复  更多评论   

为什么我的程序就是不能成功检测:
system("md test");
fp=fopen("test\\test.data","wb");
if(!fp)
exit(0);
fclose(fp);

//测试FindFirstFile()函数.
hFind=FindFirstFile((LPCWSTR)"test\\test.data",&FindFileData);
printf("%x",hFind);
printf("\n%x",INVALID_HANDLE_VALUE);
FindClose(hFind);
结果总是 ffffffff
ffffffff
文件存在,但用FindFirstFile()却检测不成功.
2007-09-05 10:51 | 胡滨

# re: 检测文件存在的四种方法。test if a File exist or not?[未登录]  回复  更多评论   

hFind=FindFirstFile((LPCWSTR)"test\\test.data",&FindFileData);

改用絕對路徑 看看?
2009-06-11 11:26 | haha

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理