简体   繁体   中英

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

i am working in LabCVI on the basis of C90.

The tanks at hand would be to find the absolute paths of "*.spec" files in the "..\\data"" directory and subdirectories.

I am aware that there are explanationse how i can do this with dirent.h, but i need to do it without 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.

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. So i cant use the directory utilities of LabCVI.

How can i work around this and get my directory access? (The Code will run on XP Machines.)

The C language itself has no concept of directories and thus no way to list or access them. 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.

You can use FindFirstFile and similar functions to do this. Check this sample code for more details: http://msdn.microsoft.com/en-us/library/aa365200%28v=vs.85%29.aspx

Vikram's answer led me to write this codesnippet wich i used.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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