简体   繁体   English

没有dirent.h的情况下如何访问C90中的目录?

[英]How can i access directories in C90 without dirent.h?

i am working in LabCVI on the basis of C90. 我在基于C90的LabCVI中工作。

The tanks at hand would be to find the absolute paths of "*.spec" files in the "..\\data"" directory and subdirectories. 当前的储罐将在“ .. \\ data”目录和子目录中找到“ * .spec”文件的绝对路径。

I am aware that there are explanationse how i can do this with dirent.h, but i need to do it without dirent.h. 我知道有人在解释我如何使用dirent.h做到这一点,但我需要在没有dirent.h的情况下做到这一点。 This ( part I , part II ) tutorial is not what i am looking for. 本教程(第一部分第二部分 )不是我想要的。 LabCVI does not feature the dirent header and i cannot import ist from the Internet because the dependencies of dirent.h are incompatible with LabCVI. LabCVI不具有dirent标头,并且我不能从Internet导入ist,因为dirent.h的依赖项与LabCVI不兼容。

I plan to migrate to a better IDE/Language once i killed all dependencies to LabCVI, but i have to keep the code campatible to that day. 一旦我杀死了对LabCVI的所有依赖关系,我计划迁移到更好的IDE /语言,但是那天我必须保持代码的可移植性。 So i cant use the directory utilities of LabCVI. 所以我不能使用LabCVI的目录实用程序。

How can i work around this and get my directory access? 我该如何解决并获得目录访问权限? (The Code will run on XP Machines.) (该代码将在XP计算机上运行。)

The C language itself has no concept of directories and thus no way to list or access them. C语言本身没有目录的概念,因此无法列出或访问它们。 If your system doesn't conform to a higher-level standard like POSIX (which specified dirent.h ) then you'll need to look for a system-specific solution. 如果您的系统不符合POSIX(指定dirent.h )等更高级别的标准,则需要寻找特定于系统的解决方案。

You can use FindFirstFile and similar functions to do this. 您可以使用FindFirstFile和类似的函数来执行此操作。 Check this sample code for more details: http://msdn.microsoft.com/en-us/library/aa365200%28v=vs.85%29.aspx 检查此示例代码以获取更多详细信息: http : //msdn.microsoft.com/zh-cn/library/aa365200%28v=vs.85%29.aspx

Vikram's answer led me to write this codesnippet wich i used. Vikram的回答使我写下了我曾经用过的这段代码。

void findSpecFilesAndPrint(void){
    HANDLE hFind;
    WIN32_FIND_DATA FindFileData;

    hFind = FindFirstFile("*.*", &FindFileData);
    if (hFind == INVALID_HANDLE_VALUE){ 
        //FOUND NO FILE
        printf("No file found.\n");
    }
    else {
        printf("Files found - one function to find them all.\n");
        do{
            //DO THIS WITH ALL FILES FOUND
            printf(FindFileData.cFileName);
            printf("\n");
        }while (FindNextFile(hFind, &FindFileData) != 0);
        printf("And in the darkness bind them.\n");
        FindClose(hFind);
    }
}

Finds all Files in the current directory 查找当前目录中的所有文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM