Well, even if the check is correct, you can never be sure that the directory still exists after the if condition has been evaluated. Another process or user can simply create or delete it. Thus, you should check if the operation has completed (possibly catch the corresponding exception).
Therefore, you should not rely on verification and always expect the worst. (Well, checks can be useful so that you do not do something unnecessary or ask the user for confirmation, etc. But they do not guarantee anything.)
source share