I recently added GetTempPath to the application. During the code review, it was emphasized that the GetTempPath description contains information:
The application should check for the path and the appropriate path permissions before any use for file I / O.
Now all access to the files is wrapped in try / catch blocks, and what system will be there that does not have access to its own temporary directory?
My initial idea would be to attempt to create directories if they do not exist (via GetFileAttributes and CreateDirectory), and then to create the file, write the byte, and then delete the file. Although this will work, it smells of ignorance - is there probably the best way to verify that you have write access to a folder?
I began to search and find file attribute constants, common permissions, standard permissions, file permissions constants and the GetSecurityInfo function. All this seemed to create a solution that was longer than creating the file and see if it adheres to the method.
So, what is the correct way to use WinAPI authentication features, do you have write access to the folder?
source share