You are here:

C++/Directory contents


I'm using Mingw compiler.

I want to know the files in a specific directory (no n "the current directory"). It must be standar C++ code (not like Microsoft's "_findfirst" and so). For a given "path", i want to receive the streams (FILE struct) of the files.

Thanks in advance

De vez en cuando, Thank you for your question.

I believe that enumerating the files in a given directory is supported only by underlying operating systems, and not available in either the C or C++ runtime libraries.

If your code will be known to run on certain platforms, it can use functions that are available on those platforms. On Linux, the 'scandir' function does wildcard matching and sorting on directory entries. On POSIX-compliant systems (Unix-flavor), there is a DIR datatype, representing an open directory (opened with 'opendir'). 'readdir' will fetch the next directory entry. On DOS-compatible systems, findfirst/findnext (sometimes preceded by an underscore), are available. Other proprietary systems have their own APIs for enumerating files, for example, Microsoft Windows uses 'FindFirstFile'/'FindNextFile'.

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.