Microsoft Visual Studio:opendir()和readdir(),如何? [英] Microsoft Visual Studio: opendir() and readdir(), how?

查看:165
本文介绍了Microsoft Visual Studio:opendir()和readdir(),如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在Dev-cpp中使用过这种代码:

I've used this kind of code in my Dev-cpp before:

if((dh = opendir(folder)) !== false){
    while((file = readdir(dh)) !== false){
        // do my stuff
    }
    closedir(dh);
}

但是现在我正在使用MSVC ++,但我不知道如何在其中添加这些文件,我试图在其中复制dirent.h/dir.h/errno.h,但是它又给出了另一个错误,这些错误与这些文件中的另一个包含文件有关文件...,并通过查看文件,我在那里看到mingw的东西,所以它的编译器相关吗? idk MSVC ++使用的编译器是什么,但是可以将这些文件复制粘贴到MSVC ++中并使其正常工作吗?

But now i am using MSVC++ and i dont know how to add those files there, i tried to copy dirent.h/dir.h/errno.h in there, but it gives another error relating to another included files inside those files ..., and by looking in the files i see mingw stuff there so its compiler related? idk what compiler MSVC++ uses, but is it possible to copypaste those files in MSVC++ and get it working?

我试图从MSDN中查找一些代码,但确实搞砸了,所以我希望我可以在上面使用这些功能...

I tried to look up some code from MSDN but it was really messed up, so im hoping i could use these functions above...

推荐答案

我建议使用示例代码:

HANDLE hFind;
WIN32_FIND_DATA FindFileData;

if((hFind = FindFirstFile("C:/some/folder/*.txt", &FindFileData)) != INVALID_HANDLE_VALUE){
    do{
        printf("%s\n", FindFileData.cFileName);
    }while(FindNextFile(hFind, &FindFileData));
    FindClose(hFind);
}

这确实更好,因为我可以使用"* .txt"等,这使得查找某些特定文件类型变得更加容易,之前我不得不为此编写自己的匹配函数:D

This really is better, because i can use "*.txt" etc, makes it much more easier to find some specific filetypes, earlier i had to write own match function for that :D

这篇关于Microsoft Visual Studio:opendir()和readdir(),如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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