我发现这么一个情况,release模式下,文件夹还没来得及生成出来,程序就接着执行了,结果很多文件没有解压出来,生成一大堆空文件夹,请问有遇类似情况的同仁么?而debug下正常。
            int nItems = ze.index;
            for(int i=0; i < nItems; i++)
            {
                memset(&ze, 0, sizeof(ze));
                GetZipItem(hZip, i, &ze);                CString strRelativeFilePathName = ze.name;
                CString strFilePathName = strRootDir + "\\" + ConvertUnixPath2DosPath(strRelativeFilePathName);
    
                CString strFileDir = extract_filedir_from_pathname(strFilePathName);                
                CString strFileName = extract_filename_from_pathname(strFilePathName);                CreateDir(strFileDir);                SetCurrentDirectory(strFileDir);
                char szFileName[MAX_PATH] = {0};
                strcpy(szFileName, strFileName);
                UnzipItem(hZip, i, (void *)szFileName, 0, ZIP_FILENAME);
                
            }
 当然,这个函数有可能也写得有问题: 
//建立目录,允许一次建立多层目录
BOOL CreateDir(const CString& strFilePath)
{    
    CString strNewFilePath(strFilePath);
    if(strNewFilePath.Right(1) != '\\')
    {
        strNewFilePath += "\\";
    }    CString tempdir("");
    char c1;
    for(int i=0; i < strNewFilePath.GetLength(); i++)
    {
        c1 = strNewFilePath.GetAt(i);
        tempdir += c1;
        if(c1 == '\\')
            ::CreateDirectory(tempdir, NULL);//先逐级建立文件夹
    }        return TRUE;
}

解决方案 »

  1.   

    不用API,用_mkdir试一试此函数也可以创建文件夹,
      

  2.   

    判断一下CreateDirectory()的返回值
      

  3.   

    for(int i=0; i < nItems; i++)
                {
                    memset(&ze, 0, sizeof(ze));
                    GetZipItem(hZip, i, &ze);                CString strRelativeFilePathName = ze.name;
                    CString strFilePathName = strRootDir + "\\" + ConvertUnixPath2DosPath(strRelativeFilePathName);
        
                    CString strFileDir = extract_filedir_from_pathname(strFilePathName);                
                    CString strFileName = extract_filename_from_pathname(strFilePathName);                if(CreateDir(strFileDir)){                SetCurrentDirectory(strFileDir);
                    char szFileName[MAX_PATH] = {0};
                    strcpy(szFileName, strFileName);
                    UnzipItem(hZip, i, (void *)szFileName, 0, ZIP_FILENAME);
                    }
                }BOOL CreateDir(const CString& strFilePath)
    {    
        CString strNewFilePath(strFilePath);
        if(strNewFilePath.Right(1) != '\\')
        {
            strNewFilePath += "\\";
        }    CString tempdir("");
        char c1;
        for(int i=0; i < strNewFilePath.GetLength(); i++)
        {
            c1 = strNewFilePath.GetAt(i);
            tempdir += c1;
            if(c1 == '\\')
                if(!::CreateDirectory(tempdir, NULL))//先逐级建立文件夹
                   return 0;
        }        return TRUE;
    }
      

  4.   

    以下函数能生成多级目录文件夹BOOL MakeDirectory(CString dd)
    {
    HANDLE fFile; // File Handle
    WIN32_FIND_DATA fileinfo; // File Information Structure
    CStringArray m_arr; // CString Array to hold Directory Structures
    BOOL tt; // BOOL used to test if Create Directory was successful
    int x1 = 0; // Counter
    CString tem = ""; // Temporary CString Object fFile = FindFirstFile(dd,&fileinfo); // if the file exists and it is a directory
    if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
    {
    //  Directory Exists close file and return
    FindClose(fFile);
    return TRUE;
    }
    m_arr.RemoveAll(); for(x1 = 0; x1 < dd.GetLength(); x1++ ) // Parse the supplied CString Directory String
    {
    if(dd.GetAt(x1) != '\\') // if the Charachter is not a \ 
    tem += dd.GetAt(x1); // add the character to the Temp String
    else
    {
    m_arr.Add(tem); // if the Character is a \ 
    tem += "\\"; // Now add the \ to the temp string
    }
    if(x1 == dd.GetLength()-1) // If we reached the end of the String
    m_arr.Add(tem);
    } // Close the file
    FindClose(fFile); // Now lets cycle through the String Array and create each directory in turn
    for(x1 = 1; x1 < m_arr.GetSize(); x1++)
    {
    tem = m_arr.GetAt(x1);
    tt = CreateDirectory(tem,NULL); // If the Directory exists it will return a false
    if(tt)
    SetFileAttributes(tem,FILE_ATTRIBUTE_NORMAL);
    // If we were successful we set the attributes to normal
    }
    //  Now lets see if the directory was successfully created
    fFile = FindFirstFile(dd,&fileinfo); m_arr.RemoveAll();
    if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
    {
    //  Directory Exists close file and return
    FindClose(fFile);
    return TRUE;
    }
    else
    {
    // For Some reason the Function Failed  Return FALSE
    FindClose(fFile);
    return FALSE;
    }
    }
      

  5.   

    CreateDir(strFileDir);之后执行一下Sleep(0);试试
      

  6.   


                if(!::CreateDirectory(tempdir, NULL))//先逐级建立文件夹
                   return 0;
    这句话害惨了。
    存在的文件夹就会返回失败的。