PDA

Просмотр полной версии : Не могу удалить папку



AlexDav
10.11.2005, 13:50
void CStrageDlg::OnBnClickedOk()
{
CFileFind finderfile;
CStringW strName("*.*");
CString strPath;
::SetCurrentDirectory(_T("C:\\"));

if(finderfile.FindFile(strName,0))
{

while(finderfile.FindNextFileW())
{
if(finderfile.IsDirectory())
{
CString strN = finderfile.GetFileName();
if(strN.CompareNoCase(_T("Delthise"))==0)
{
strPath = finderfile.GetFilePath();
strPath.Replace(_T("\\"),_T("\\\\"));
SetDlgItemTextW(IDC_STATIC,strPath);
CFileStatus status;
status.m_attribute = 0;
CFile::SetStatus(strPath, status);
SHFILEOPSTRUCT fa;
fa.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION;
fa.hNameMappings = NULL;
fa.hwnd = m_hWnd;
fa.pFrom = strPath;
fa.pTo = NULL;
fa.wFunc = FO_DELETE;
int nRes = ::SHFileOperation(&fa);

}

}
}
}


}



Почему не удаляется папка?
Может есть еще способы удалить папку с файлами - мне надо даже в том случае если какие-нибудь из вложенных файлов запущены и т.п.

Eugie
11.11.2005, 13:41
Строковые значения для pFrom и pTo в SHFILEOPSTRUCT должны завершаться парой символов NULL, цитата:


typedef struct _SHFILEOPSTRUCT {
HWND hwnd;
UINT wFunc;
LPCTSTR pFrom;
LPCTSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCTSTR lpszProgressTitle;
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;
.....
pFrom
Address of a buffer to specify one or more source file names. These names must be fully qualified paths. Standard Microsoft® MS-DOS® wild cards, such as "*", are permitted in the file-name position. Although this member is declared as a null-terminated string, it is used as a buffer to hold multiple file names. Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom.
pTo
Address of a buffer to contain the name of the destination file or directory. This parameter must be set to NULL if it is not used. Like pFrom, the pTo member is also a double-null terminated string and is handled in much the same way. However, pTo must meet the following specifications.
.....


Вот так должно работать:


void CStrageDlg::OnBnClickedOk()
{
CFileFind finderfile;
LPCTSTR ptzFold = _T("Delthise\0");
CString strPath;
::SetCurrentDirectory(_T("C:\\"));

if(finderfile.FindFile("*.*",0))
{
while(finderfile.FindNextFile())
{
if(finderfile.IsDirectory())
{
CString strN = finderfile.GetFileName();
if(strN.CompareNoCase(ptzFold)==0)
{
strPath = finderfile.GetFilePath();
SetDlgItemText(IDC_STATIC, strPath);
SHFILEOPSTRUCT fa;
fa.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION;
fa.hNameMappings = NULL;
fa.hwnd = m_hWnd;
fa.pFrom = ptzFold;
fa.pTo = NULL;
fa.wFunc = FO_DELETE;
int nRes = ::SHFileOperation(&fa);
}
}
}
}
}

AlexDav
14.11.2005, 11:16
Спасибо. Все действительно так - и почему я никогда до конца не читаю :oops: