C ++有没有办法监视目录中的新文件? [英] C++ Is there any way to monitor for new files in directory?

查看:77
本文介绍了C ++有没有办法监视目录中的新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在编写程序,其目的是计算指定目录中的文件,当出现新文件时,它应该获取此文件名并存储它。我的问题是我怎么能这样做? :O



PS:我的操作系统是Windows7,我也安装了boost c ++ libs。

Hello everyone!
I'm writing program whose purpose to count files in specified directory and when appear new file it should get this file name and store it. My question is how could i do it? :O

PS: My OS is Windows7, also i have installed boost c++ libs.

推荐答案

对于Windows来说当然可以做到。 Stackoverflow问题页面顶部有一个非常好的答案: http://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c [ ^ ]。



不幸的是,我不知道一个增强解决方案,唯一的跨平台解决方案是在Trolltech的Qt中。



-SA
It is certainly possible to do for Windows. A very good answer is on the top of this Stackoverflow question page: http://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c[^].

Unfortunately, I don't know a boost solution, and the only cross-platform solution is in Trolltech's Qt.

—SA


您正在寻找更改通知。请参阅 http://msdn.microsoft上的示例。 com / zh-CN / library / windows / desktop / aa365261%28v = vs.85%29.aspx [ ^ ]



希望这有帮助。
You're looking for change notifications. See the example at http://msdn.microsoft.com/en-us/library/windows/desktop/aa365261%28v=vs.85%29.aspx[^]

Hope that helps.


几年前我不得不弄清楚同样的事情。我读到/尝试过一堆不同的API。我最终使用了 ReadDirectoryChangesW API。所有其他方法都存在某种问题。
I had to figure out the same thing a couple years ago. I read about / tried a bunch of different APIs. I ended up using the ReadDirectoryChangesW API. All of the other methods had problems of some sort.


这篇关于C ++有没有办法监视目录中的新文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆