0

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.)

Johannes
  • 6,490
  • 10
  • 59
  • 108

3 Answers3

4

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.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
1

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.exe
  • 4,565
  • 3
  • 29
  • 40
1

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

Johannes
  • 6,490
  • 10
  • 59
  • 108
  • I used this in a different context and it turns out that for some compilers (VS2010) you have to actively convert wchar to cahr and back. Symptoms include only getting one letter filemanes. – Johannes Oct 30 '12 at 23:12