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

网友投稿 807 2022-10-22

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

检测文件存在的四种方法。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 #include #include 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" ); }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于@Query注解的用法(Spring Data JPA)
下一篇:「软件设计」权威领域驱动设计(DDD)简介
相关文章

 发表评论

暂时没有评论,来抢沙发吧~