更复杂的可以用FindFirstFileEx:HANDLE FindFirstFileEx( LPCTSTR lpFileName, // pointer to the name of the file to // search for FINDEX_INFO_LEVELS fInfoLevelId, // information level of the returned data LPVOID lpFindFileData, // pointer to the returned information FINDEX_SEARCH_OPS fSearchOp, // type of filtering to perform LPVOID lpSearchFilter, // pointer to search criteria DWORD dwAdditionalFlags // additional search control flags );详细的看 MSDN 吧!
或者你可以用CFileStation
HANDLE FindFirstFile(
LPCTSTR lpFileName, // file name
LPWIN32_FIND_DATA lpFindFileData // data buffer
);例子如下:
#define _WIN32_WINNT 0x0400#include "windows.h"int
main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind; printf ("Target file is %s.\n", argv[1]); hFind = FindFirstFile(argv[1], &FindFileData); if (hFind == INVALID_HANDLE_VALUE) {
printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
} else {
printf ("The first file found is %s\n", FindFileData.cFileName);
FindClose(hFind);
} return (0);
}
FILE *fp;
//
char szPath;
fp = fopen(szPath, "r")if (fp)
{
//存在
fclose(fp);
}
else
{//不存在
}
LPCTSTR lpFileName, // pointer to the name of the file to
// search for
FINDEX_INFO_LEVELS fInfoLevelId,
// information level of the returned data
LPVOID lpFindFileData, // pointer to the returned information
FINDEX_SEARCH_OPS fSearchOp,
// type of filtering to perform
LPVOID lpSearchFilter, // pointer to search criteria
DWORD dwAdditionalFlags // additional search control flags
);详细的看 MSDN 吧!