Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > CString -> LPCSTR


Автор: Sailos 16.4.2007, 15:07
Добрый день, тема уже была, но всёже...
Вот мой код:
Код

CString str, str1, execute;
    str.Format("Z:\\*.*");
    _finddata_t data;
    intptr_t path = _findfirst (str,&data);
    if (path != -1)
    {
        CString tt = strstr(data.name,_T("."));
        if (tt != _T("."))
            MessageBox(data.name);
        while (_findnext(path,&data)== 0)
        {
            tt = strstr(data.name,"..");
            if (tt != "..")
            {
                str1.Format("Z:\\%s\\TEMP\\*.*",data.name);
                _finddata_t nextf;
                intptr_t put = _findfirst (str1,&nextf);
                if (put != -1)
                {
                    while (_findnext(put,&nextf)== 0)
                    {
                        tt = "";
                        tt = strstr(nextf.name,"..");
                        if (tt != "..")
                        {
                            if (nextf.attrib == 16)
                            {
                                CString temper;
                                temper.Format("%s",nextf.name);
                                if (temper.Mid(0,4) == "2007")
                                {
                                    execute.Format("Z:\\%s\\TEMP\\%s\0",data.name,nextf.name);
                                    SHFILEOPSTRUCT fa;
                                    fa.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION;
                                    fa.hNameMappings = NULL;
                                    fa.hwnd = m_hWnd;
                                    fa.pFrom = (LPCSTR)execute;
                                    fa.pTo = NULL;
                                    fa.wFunc = FO_DELETE;
                                    int nRes = ::SHFileOperation(&fa);
                                }
                            }
                        }
                    }
                }
                _findclose(put);
            }
        }
        MessageBox("Готово!");
    }

Подскажите почему не работает?
Заранее благодарен!!!

Автор: vinter 16.4.2007, 15:16
что конкретно не работает? телепаты в отпуске

Автор: Sailos 16.4.2007, 15:21
Цитата(vinter @ 16.4.2007,  15:16)
что конкретно не работает? телепаты в отпуске

 smile  smile 
не удаляет ни одну папку, хотя папки есть.
И если убрать FOF_NOERRORUI, выдаёт 
Цитата

не удаётся удалить файл. Не удаётся произвести чтение из файла или с диска.

Автор: Sailos 16.4.2007, 15:44
Спасибо за внимание!!!
Разобрался smile
нужно так:
Код

execute.Format("Z:\\%s\\TEMP\\%s",data.name,nextf.name);
execute += '/0';
SHFILEOPSTRUCT fa;
fa.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION;
fa.hNameMappings = NULL;
fa.hwnd = m_hWnd;
fa.pFrom = (LPCSTR)execute;
fa.pTo = NULL;
fa.wFunc = FO_DELETE;
int nRes = ::SHFileOperation(&fa);

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)