I'm writing a C program which performs operations on various files within directories. I'd like to be able to obtain a listing of files contained in a specific directory.
The tricky bit is, I'm trying to make the code as portable as possible. I know that under DOS I can call a DOS-specific function, and that under UNIX I can parse the output of 'ls' (or other system calls).
However, is there a better method than simply using preprocessor commands such as #define DOS 1 and then using #ifdef DOS ... #else ... #endif on huge blocks of code? It doesn't strike me as 'elegant' as I'd in effect be defining two different source codes and selecting the one to use at compile-time. Is there a better solution?