I need to write to a file in a nested directory that may or may not exist.
At first, I checked if the folder existed via os.Stat
, doing os.MkdirAll
if it doesn't exist, and then opening and writing to a file.
I tried removing the os.Stat and just doing os.MkdirAll
, and it appears to work - meaning os.MkdirAll
is idempotent.
My question is, is there a benefit of doing the os.Stat
check? Is it a much lighter operation than os.MkdirAll
?