Delete subfolder
-
Weird problem I have this function (is a function changed I used it to another purpose)
void browseFolder(TCHAR *path, TCHAR *initial)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=INVALID_HANDLE_VALUE;
TCHAR dir[MAX_PATH];
TCHAR aux[MAX_PATH];
StringCchCopy(aux, MAX_PATH, path);
StringCchCat(aux, MAX_PATH, TEXT("\\*"));
hFind= FindFirstFile(aux,&FindFileData);//browse the folder do { if (FindFileData.dwFileAttributes & FILE\_ATTRIBUTE\_DIRECTORY) { if((\_tcscmp (FindFileData.cFileName, \_T(".")) != 0) && (\_tcscmp (FindFileData.cFileName, \_T("..")) != 0)) { //if is a subfolder we need to change the path and we call the function again //change path StringCchCopy(dir, MAX\_PATH, path); StringCchCat(dir, MAX\_PATH, TEXT("\\\\")); StringCchCat(dir, MAX\_PATH, FindFileData.cFileName); // oldPat\\\\dirName //\_tprintf(TEXT("\\n
%s\n"), FindFileData.cFileName);
browseFolder(dir,initial); //if is folder we call the function again} } else { //files we delete it //set the current directory for copping the file //create the correct path name for the files that will be downloaded TCHAR pathFileName\[MAX\_PATH\]; StringCchCopy(pathFileName, MAX\_PATH, path); StringCchCat(pathFileName, MAX\_PATH, TEXT("\\\\")); StringCchCat(pathFileName, MAX\_PATH, FindFileData.cFileName); CString szMessage; szMessage.Format(\_T("%s"),pathFileName); \_tprintf(\_T("%s\\n"),szMessage); DeleteFile(szMessage); } } while (FindNextFile(hFind, &FindFileData) != 0); // delete &FindFileData; hFind= INVALID\_HANDLE\_VALUE; \_tprintf(path); RemoveDirectory(path);
}
The function delete all the files but lives the folders intact I cannot understand why. Seems like they are in use and they cannot be deleted....
-
Weird problem I have this function (is a function changed I used it to another purpose)
void browseFolder(TCHAR *path, TCHAR *initial)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=INVALID_HANDLE_VALUE;
TCHAR dir[MAX_PATH];
TCHAR aux[MAX_PATH];
StringCchCopy(aux, MAX_PATH, path);
StringCchCat(aux, MAX_PATH, TEXT("\\*"));
hFind= FindFirstFile(aux,&FindFileData);//browse the folder do { if (FindFileData.dwFileAttributes & FILE\_ATTRIBUTE\_DIRECTORY) { if((\_tcscmp (FindFileData.cFileName, \_T(".")) != 0) && (\_tcscmp (FindFileData.cFileName, \_T("..")) != 0)) { //if is a subfolder we need to change the path and we call the function again //change path StringCchCopy(dir, MAX\_PATH, path); StringCchCat(dir, MAX\_PATH, TEXT("\\\\")); StringCchCat(dir, MAX\_PATH, FindFileData.cFileName); // oldPat\\\\dirName //\_tprintf(TEXT("\\n
%s\n"), FindFileData.cFileName);
browseFolder(dir,initial); //if is folder we call the function again} } else { //files we delete it //set the current directory for copping the file //create the correct path name for the files that will be downloaded TCHAR pathFileName\[MAX\_PATH\]; StringCchCopy(pathFileName, MAX\_PATH, path); StringCchCat(pathFileName, MAX\_PATH, TEXT("\\\\")); StringCchCat(pathFileName, MAX\_PATH, FindFileData.cFileName); CString szMessage; szMessage.Format(\_T("%s"),pathFileName); \_tprintf(\_T("%s\\n"),szMessage); DeleteFile(szMessage); } } while (FindNextFile(hFind, &FindFileData) != 0); // delete &FindFileData; hFind= INVALID\_HANDLE\_VALUE; \_tprintf(path); RemoveDirectory(path);
}
The function delete all the files but lives the folders intact I cannot understand why. Seems like they are in use and they cannot be deleted....
HEY ! how many times are you going to ask this ? can't you follow the same thread ? it's not a chat buddy, it's a forum. so ask you question, and wait !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Weird problem I have this function (is a function changed I used it to another purpose)
void browseFolder(TCHAR *path, TCHAR *initial)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=INVALID_HANDLE_VALUE;
TCHAR dir[MAX_PATH];
TCHAR aux[MAX_PATH];
StringCchCopy(aux, MAX_PATH, path);
StringCchCat(aux, MAX_PATH, TEXT("\\*"));
hFind= FindFirstFile(aux,&FindFileData);//browse the folder do { if (FindFileData.dwFileAttributes & FILE\_ATTRIBUTE\_DIRECTORY) { if((\_tcscmp (FindFileData.cFileName, \_T(".")) != 0) && (\_tcscmp (FindFileData.cFileName, \_T("..")) != 0)) { //if is a subfolder we need to change the path and we call the function again //change path StringCchCopy(dir, MAX\_PATH, path); StringCchCat(dir, MAX\_PATH, TEXT("\\\\")); StringCchCat(dir, MAX\_PATH, FindFileData.cFileName); // oldPat\\\\dirName //\_tprintf(TEXT("\\n
%s\n"), FindFileData.cFileName);
browseFolder(dir,initial); //if is folder we call the function again} } else { //files we delete it //set the current directory for copping the file //create the correct path name for the files that will be downloaded TCHAR pathFileName\[MAX\_PATH\]; StringCchCopy(pathFileName, MAX\_PATH, path); StringCchCat(pathFileName, MAX\_PATH, TEXT("\\\\")); StringCchCat(pathFileName, MAX\_PATH, FindFileData.cFileName); CString szMessage; szMessage.Format(\_T("%s"),pathFileName); \_tprintf(\_T("%s\\n"),szMessage); DeleteFile(szMessage); } } while (FindNextFile(hFind, &FindFileData) != 0); // delete &FindFileData; hFind= INVALID\_HANDLE\_VALUE; \_tprintf(path); RemoveDirectory(path);
}
The function delete all the files but lives the folders intact I cannot understand why. Seems like they are in use and they cannot be deleted....
Did you try GetLastError() or check that whether the files have been deleted completely before calling RemoveDirectory(). Try putting some Sleep(interval) between deleting files and the folder if you want to test this
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Weird problem I have this function (is a function changed I used it to another purpose)
void browseFolder(TCHAR *path, TCHAR *initial)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=INVALID_HANDLE_VALUE;
TCHAR dir[MAX_PATH];
TCHAR aux[MAX_PATH];
StringCchCopy(aux, MAX_PATH, path);
StringCchCat(aux, MAX_PATH, TEXT("\\*"));
hFind= FindFirstFile(aux,&FindFileData);//browse the folder do { if (FindFileData.dwFileAttributes & FILE\_ATTRIBUTE\_DIRECTORY) { if((\_tcscmp (FindFileData.cFileName, \_T(".")) != 0) && (\_tcscmp (FindFileData.cFileName, \_T("..")) != 0)) { //if is a subfolder we need to change the path and we call the function again //change path StringCchCopy(dir, MAX\_PATH, path); StringCchCat(dir, MAX\_PATH, TEXT("\\\\")); StringCchCat(dir, MAX\_PATH, FindFileData.cFileName); // oldPat\\\\dirName //\_tprintf(TEXT("\\n
%s\n"), FindFileData.cFileName);
browseFolder(dir,initial); //if is folder we call the function again} } else { //files we delete it //set the current directory for copping the file //create the correct path name for the files that will be downloaded TCHAR pathFileName\[MAX\_PATH\]; StringCchCopy(pathFileName, MAX\_PATH, path); StringCchCat(pathFileName, MAX\_PATH, TEXT("\\\\")); StringCchCat(pathFileName, MAX\_PATH, FindFileData.cFileName); CString szMessage; szMessage.Format(\_T("%s"),pathFileName); \_tprintf(\_T("%s\\n"),szMessage); DeleteFile(szMessage); } } while (FindNextFile(hFind, &FindFileData) != 0); // delete &FindFileData; hFind= INVALID\_HANDLE\_VALUE; \_tprintf(path); RemoveDirectory(path);
}
The function delete all the files but lives the folders intact I cannot understand why. Seems like they are in use and they cannot be deleted....
I do not see that you heeded the earlier suggestion of calling
FindClose(hfind)
."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I do not see that you heeded the earlier suggestion of calling
FindClose(hfind)
."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne