SearchSubdir(LPCSTR lpszFolderPath)
{
char strname[MAX_PATH] = ""; //file name
char strsearch[MAX_PATH] = ""; //search name
char strdir[MAX_PATH] = ""; //dir path
char strfile[MAX_PATH] = ""; //file path
if (GetFileAttributesA(lpszFolderPath) & FILE_ATTRIBUTE_DIRECTORY)
{
strcpy(strsearch, lpszFolderPath);
HANDLE hFile;
WIN32_FIND_DATAA wfd;
strcat(strsearch, "//*.*");
hFile = FindFirstFileA(strsearch, &wfd);
if (INVALID_HANDLE_VALUE == hFile)
return;
do
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
sprintf(strname, wfd.cFileName);
//排除掉两个文件夹
if(lstrcmpA(wfd.cFileName, ".") == 0 || lstrcmpA(wfd.cFileName,"..") == 0)
continue;
strcpy(strdir, lpszFolderPath);
strcat(strdir, "//");
strcat(strdir, strname);
SearchSubdir(strdir);
}
else
{
memset(strfile, NULL, MAX_PATH);
strcat(strfile, lpszFolderPath);
strcat(strfile, "//");
strcat(strfile, wfd.cFileName);
SetFileAttributesA(strfile, FILE_ATTRIBUTE_NORMAL);
m_pClientInfo->fileInfo.fileList.push_back(strfile);
}
} while (FindNextFileA(hFile, &wfd));
}
}
CreateDirectory(IN LPCTSTR lpszDirName)
{
LPTSTR p, pszDirCopy;
DWORD dwAttributes;
// Make a copy of the string for editing.
__try
{
pszDirCopy = (LPTSTR)malloc(sizeof(TCHAR) * (lstrlen(lpszDirName) + 1));
if(pszDirCopy == NULL)
return FALSE;
lstrcpy(pszDirCopy, lpszDirName);
p = pszDirCopy;
// If the second character in the path is "/", then this is a UNC
// path, and we should skip forward until we reach the 2nd / in the path.
if((*p == TEXT('//')) && (*(p+1) == TEXT('//')))
{
p++; // Skip over the first / in the name.
p++; // Skip over the second / in the name.
// Skip until we hit the first "/" (//Server/).
while(*p && *p != TEXT('//'))
{
p = CharNext(p);
}
// Advance over it.
if(*p)
{
p++;
}
// Skip until we hit the second "/" (//Server/Share/).
while(*p && *p != TEXT('//'))
{
p = CharNext(p);
}
// Advance over it also.
if(*p)
{
p++;
}
}
else if(*(p+1) == TEXT(':')) // Not a UNC. See if it's <drive>:
{
p++;
p++;
// If it exists, skip over the root specifier
if(*p && (*p == TEXT('//')))
{
p++;
}
}
while(*p)
{
if(*p == TEXT('//'))
{
*p = TEXT('/0');
dwAttributes = GetFileAttributes(pszDirCopy);
// Nothing exists with this name. Try to make the directory name and error if unable to.
if(dwAttributes == 0xffffffff)
{
if(!::CreateDirectory(pszDirCopy, NULL))
{
if(GetLastError() != ERROR_ALREADY_EXISTS)
{
free(pszDirCopy);
return FALSE;
}
}
}
else
{
if((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
{
// Something exists with this name, but it's not a directory... Error
free(pszDirCopy);
return FALSE;
}
}
*p = TEXT('//');
}
p = CharNext(p);
}
dwAttributes = GetFileAttributes(pszDirCopy);
if(dwAttributes == 0xffffffff)
{
if(!::CreateDirectory(pszDirCopy, NULL))
{
if(GetLastError() != ERROR_ALREADY_EXISTS)
{
free(pszDirCopy);
return FALSE;
}
}
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
// SetLastError(GetExceptionCode());
free(pszDirCopy);
return FALSE;
}
free(pszDirCopy);
return TRUE;
}