使用CFtpFileFind的FindFile函数,找不到已经存在的文件夹

CSMCLUO 2009-04-10 08:59:50
我用CFtpFileFind的FindFile函数查看FTP服务器上根目录下是否已经存在某个同名目录
奇怪的是,在试过的很多台机器中,有一台当查找的目录存在且是空目录时,FindFile返回的是FALSE,而如果这个目录不空时,查找返回TRUE
暂时只在一台机器上出现了这个问题,不理解是什么回事
为此特意写了个段简单的代码,先建立一个空目录,然后查找该目录是否存在,结果还是返回FALSE
不明白原因,希望有大侠能帮忙
代码如下


#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>
#include <string>


CString m_host = "192.168.1.187"; //ftp地址
CString m_username = "user";//用户名
CString m_password = "upfile";//密码
int m_port = 21;//端口

CInternetSession *m_pInetSession;//WinInet类之一,创建并初始化Internet会话
CFtpConnection *m_pFtpConnection;//建立Ftp连接

m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);

try
{
m_pFtpConnection=m_pInetSession->GetFtpConnection(m_host,m_username,m_password,m_port);
}
catch(...)
{
m_pFtpConnection=NULL;
}

if(m_pFtpConnection!=NULL)
{
string folder = "2009-4-4";
LPCTSTR Url = folder.c_str();
CFtpFileFind finder(m_pFtpConnection);

BOOL res=finder.FindFile(_T(url));

res = m_pFtpConnection->CreateDirectory(url);
if (res == TRUE)
{
AfxMessageBox("创建目录成功!");
}
else
{
AfxMessageBox("创建目录失败!");
}

res = finder.FindFile(url);
if (res == TRUE)
{
AfxMessageBox("查找成功!");
}
else
{
AfxMessageBox("查找失败!");
}
finder.Close();
m_pFtpConnection->Close();
delete m_pFtpConnection;
delete m_pInetSession;
}
...全文
315 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hityct1 2009-04-14
  • 打赏
  • 举报
回复
还要至少调用一次FindNextFile

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧