VC 怎样判断一个文件夹是否存在?
来源:百度知道 编辑:UC知道 时间:2024/09/28 08:17:15
楼上说的不对,有API的。
DirExists(sPath);
CFileFind::FindFile
virtual BOOL FindFile( LPCTSTR pstrName = NULL, DWORD dwUnused = 0 );
Return Value
Nonzero if successful; otherwise 0. To get extended error information, call the Win32 functionGetLastError.
FILE* fp=fopen("writeinf.txt","r");
if(fp==NULL)//就是不存在writeinf.txt了
{
......
}
else //存在文件writeinf.txt
fclose(fp);
PathFileExists()函数, 例子如下:
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
void main( void )
{
// Valid file path name (file is there).
char buffer_1[] = "C:\\TEST\\file.txt";
char *lpStr1;
lpStr1 = buffer_1;
// Invalid file path name (file is not there).
char buffer_2[] = "C:\\TEST\\file.doc&