Discussion Overview
The discussion revolves around methods for efficiently checking the existence of files in C++. Participants explore various approaches and functions available in different operating systems, including Unix and Windows, while addressing performance concerns related to file handling.
Discussion Character
- Technical explanation
- Debate/contested
- Exploratory
Main Points Raised
- One participant describes a situation where checking for file existence using
fopen is slow and seeks faster alternatives.
- Another participant suggests using
stat from sys/stat.h to check file existence, noting that it may not be available on Windows.
- A different approach for Windows is proposed, using
System::IO::File::Exists, which returns a boolean indicating file existence.
- Concerns are raised about differences in function names between Unix and Windows, specifically mentioning
_fstat as a Microsoft-specific alternative to stat.
- A participant clarifies that the return values of
stat may be counterintuitive, as it returns -1 for non-existing files and 0 for existing files.
- Another participant acknowledges that their initial performance issues were due to other I/O operations in their code, not the file existence check itself.
- Additional methods are mentioned, such as using
access from unistd.h, though its compatibility with Windows is questioned.
- A later reply humorously points out that some responses are to older posts, emphasizing the ongoing relevance of checking file existence.
Areas of Agreement / Disagreement
Participants present multiple competing views on the best method to check for file existence, with no consensus reached on a single preferred approach. There is acknowledgment of the differences in function availability and behavior across operating systems.
Contextual Notes
Limitations include potential confusion over return values of functions like stat, as well as the need to adapt code when porting between Unix and Windows due to differing function names.