我写了个函数来判断FTP上的文件夹是否存在,如下:bool FtpModule::IsFolderExist( const char* szFolder )
{
CFtpFileFind ff(m_pFtp);
if ( !ff.FindFile( szFolder ) )
{
// 抛异常
}
if ( !ff.FindNextFile() )
{
return false;
}

if ( !ff.IsDirectory() )
{
return false;
}

return true;
}但是实际运行中,很多时候文件夹明明存在,也会在 FindNextFile() 那里返回false。
这是怎么回事呢?我这样写有问题吗?

解决方案 »

  1.   

    FindFile()的第二个参数默认为INTERNET_FLAG_RELOAD,会从你的本地缓存中读取,如果本地缓存与FTP上的目录结构不同,可能会使查找结果不同,可使用其他参数试试。
      

  2.   

    virtual BOOL FindFile(
       LPCTSTR pstrName = NULL,
       DWORD dwFlags = INTERNET_FLAG_RELOAD 
    );
     Parameters
    pstrName
    A pointer to a string containing the name of the file to find. If NULL, the call will perform a wildcard search (*). dwFlags
    The flags describing how to handle this session. These flags can be combined with the bitwise OR operator (|) and are as follows: INTERNET_FLAG_RELOAD   Get the data from the wire even if it is locally cached. This is the default flag. INTERNET_FLAG_DONT_CACHE   Do not cache the data, either locally or in any gateways. INTERNET_FLAG_RAW_DATA   Override the default to return the raw data (WIN32_FIND_DATA structures for FTP). INTERNET_FLAG_SECURE   Secures transactions on the wire with Secure Sockets Layer or PCT. This flag is applicable to HTTP requests only. INTERNET_FLAG_EXISTING_CONNECT   If possible, reuse the existing connections to the server for new FindFile requests instead of creating a new session for each request. 
      

  3.   

    仔细看了MSDN,原来FindNextFile()的返回值是表示“当前项之后有没有下一项”……
    我现在直接忽略了它的返回值……貌似可以了~