Re: How do I check the existence of a file programmatically in C?q~~.
From: Giorgos Keramidas (keramida_at_ceid.upatras.gr)
Date: 01 Sep 2005 22:48:18 +0300
Anton Petrusevich <email@example.com> writes:
>M?ns Rullg?rd wrote:
>> Just because not everybody needs it, it isn't a good idea to add extra
>> code to get rid of it.
> It depends. Suppose we have:
> void read_data(const char *fdata)
> int main()
> for(i = 0; i < NUMOF(datafiles); ++i)
> if(access(datafiles[i], R_OK) == 0)
> I think it's perfectly ok to check existence of a file before calling
> supposedly heavy function read_data().
That looks a lot like a micro-optimization, and these are, in general,
only justified if they're backed with real experimental data that shows
the micro-optimization *is*, in fact, required.
Not to mention that the fictitious read_data() function is not only
expensive, but a bit maldesigned, having no meaningful way to return
success or failure :P