Most likely this is because it cant find the file you are trying to open, this is what the POSIX enoent
error means. It is even more explicit when you used cygwin. The erlang badmatch
error comes from line 23:
{ok, Hdl} = file:open(TargetFile, [write, delayed_write]),
where you try to open the file and match on {ok, Hld}
. However file:open
returns {error,enoent}
when can't find the file, which causes the match to fail and generate the erlang error.
EDIT:
As I see it the problem is the file it is trying to write. Are you allowed to write in that directory? If the file already exists are you allowed to open it for writing?