Reputation: 163
I know this is a frequently asked question, but most solutions I have found are from 6-10 years ago and don't seem to work.
As a part of the C program I am writing in Visual Studio, I need to find a function that is able to return a boolean value - whether or not a file with a given name exists (the file in question is located in the debug directory, which is why I am saying file name and not file path). I need to implement it using a library I am able to include in VS, hence using access() from the unistd.h library will not work. Also, it has to be a safe function. If there's a function in the WINAPI that does all of that - that would be best.
Thanks in advance for the help.
Upvotes: 0
Views: 711
Reputation: 2609
PathFileExistsW should do the job. It takes the path of the file or directory, which you want to check the existence of, as the first argument. It returns BOOL (TRUE, if the file or directory exists, and FALSE, if it doesn't. You have to include shlwapi.h as header and link against Shlwapi.lib in order to use this function.
Upvotes: 1