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

查看:23
本文介绍了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 的东西,所以它的编译器相关?不知道 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...

推荐答案

我建议使用 FindFirstFile()FindNextFile().

示例代码:

HANDLE hFind;
WIN32_FIND_DATA FindFileData;

if((hFind = FindFirstFile("C:/some/folder/*.txt", &FindFileData)) != INVALID_HANDLE_VALUE){
    do{
        printf("%s
", 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天全站免登陆