Не могу удалить папку

Общие вопросы, не зависящие от языка реализации.

Модераторы: Duncon, Hawk, Romeo, Eugie

Ответить
AlexDav
Сообщения: 34
Зарегистрирован: 18 окт 2005, 15:37

10 ноя 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
Сообщения: 707
Зарегистрирован: 17 фев 2004, 23:59
Откуда: SPb

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
Сообщения: 34
Зарегистрирован: 18 окт 2005, 15:37

14 ноя 2005, 11:16

Спасибо. Все действительно так - и почему я никогда до конца не читаю :o ops:
Ответить