我正在开发一个C程序,它会自动将我的工作备份到我的FTP服务器上 . 到目前为止,我可以通过使用此文件指定文件名来上传单个文件
CString strFilePath = szFile ;
int iPos = strFilePath.ReverseFind('\\');
CString strFileName = strFilePath.Right((strFilePath.GetLength()- iPos-1) );
CString strDirPath = m_szFolderDroppedIn ;
strDirPath = strDirPath.Mid(0,strDirPath.GetLength() - 1);
int iPost = strDirPath.ReverseFind('\\');
CString strDirName = strDirPath.Right((strDirPath.GetLength()- iPost -1) );
bool curdir = ftpclient.SetServerDirectory((char*)strDirName.GetBuffer(strDirName.GetLength()));
//Upload to Server
int uploadret = ftpclient.PutFile(szFile,(char*)strFileName.GetBuffer(strFileName.GetLength()),0,true,dwLastError);
m_lsDroppedFiles.RemoveAll();
break;
}
现在我希望能够遍历一个目录(包含子目录)并递归调用 . 我在获取目录中的文件时遇到问题 .
任何帮助或代码段......
2 回答
@Swapnil:如果你使用
boost::filesystem
,那就是recursive_directory_iterator
由于您使用的是MFC,因此可以使用CFileFind类 . 示例代码在MSDN中给出 . 或者,您也可以使用boost.filesystem .