[英]C++ iterating through files and directories
我正在使用一個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;
}
現在,我希望能夠遍歷目錄(包含子目錄)並遞歸調用。 我在保留目錄中的文件時遇到問題。
任何幫助或代碼段...
由於使用的是MFC,因此可以使用CFileFind類。 示例代碼在MSDN中給出。 另外,您也可以使用boost.filesystem 。
@Swapnil:如果使用boost::filesystem
,則有一個recursive_directory_iterator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.