C++包含所有文件信息的文件列表
我计划制作一个程序,可以在我的计算机上的文件夹和我的 NAS 之间运行。 它会列出两个文件夹中的所有文件,然后确定哪个文件较新,然后将其上传到其他设备。 我知道如何通过 FTP 上传文件,但我一开始就卡住了,因为我不知道如何列出我的文件。我稍微研究了一下如何使用 FindFirstFile()
和 FindNextFile()
以及 WIN32_FIND_DATA
。这样,我可以获得最后写入的数据,但这不允许我列出子目录。 您是否知道列出文件夹及其子目录中的所有文件并将每个文件的信息保存在列表中的简单方法?
I'm planning to make a program that would work between a folder on my computer and my NAS.
It would list all the files in both folders, then determine which file is newer, and then upload it to the other device.
I know how to upload files via FTP, but I'm stuck at the start, because I don't know how to list my files. I have looked a little at using FindFirstFile()
and FindNextFile()
with WIN32_FIND_DATA
. This way, I can get the last write data, but this doesn't let me list subdirectories.
Do you know any easy way listing all files in a folder and its subdirectory and saving the information of every file in a list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是使用 <代码>boost::recursive_directory_iterator。
The easy way is to use
boost::recursive_directory_iterator
.FindFirstFile()
和FindNextFile()
确实可以让您列出子目录。WIN32_FIND_DATA
的成员之一是dwFileAttributes
,它将包含目录条目的FILE_ATTRIBUTE_DIRECTORY
。只需在该子目录中启动另一个FindFirstFile()
,冲洗,重复即可。MSDN 上有一个示例演示如何使用
FindFirstFile
API,此处。FindFirstFile()
andFindNextFile()
does let you list subdirectories. One of the members ofWIN32_FIND_DATA
isdwFileAttributes
which will includeFILE_ATTRIBUTE_DIRECTORY
for a directory entry. Simply start anotherFindFirstFile()
in that subdirector, rinse, repeat.There is a sample on MSDN that shows how to use the
FindFirstFile
API, here.