gpt4 book ai didi

C++ 遍历文件和目录

转载 作者:行者123 更新时间:2023-11-28 08:27:20 27 4
gpt4 key购买 nike

我正在开发一个 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类(class)。示例代码在 MSDN 中给出。或者,您可以使用 boost.filesystem同样。

关于C++ 遍历文件和目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3499446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com