Joe Wright said:
Windows:
system("dir /b > file.lst");
Linux:
system("ls > file.lst");
might do it.
Or it might not.
<OT>
In both cases, the command applies only to the current directory,
whatever that happens to be. The Unix command skips any files whose
names start with '.'. The order in which the files are listed may or
may not depend on the current locale. Either command will fail if you
don't have write permission in the current directory. If "file.lst"
already exists, the command will either clobber it or fail; if it
doesn't exist, you've just added a new file that may or may not show
up in the listing.
</OT>
Since you've provided different solutions for Windows and Linux, it's
obviously not "purely platform independent", which is what the OP was
asking for. The fact that you're using the standard function system()
doesn't make the code platform independent; it merely delays any
failure until execution time.
There is no purely platform independent solution.
Both Windows and Linux provide system-specific mechanisms for
retrieving a list of files (the Linux solution should work on any
Unix-like system). These mechanisms are far more flexible, and they
don't depend on creating and reading a temporary file in the very
directory you're trying to examine
This is one of those cases where trying to write portable code is a
waste of time; the non-portable solutions work better, and the
seemingly portable solution isn't portable at all.