I just realized that the script doesn’t work properly when the parent directory does not exist. I just created the parent directory and the code is running successfully. I think the code should be modified to either give an error message or create the directory if it does not exist.
Fixed here. From the next nightly version, it should raise an error.
I don’t think there is a good way to check/create intermediate paths before opening a file in the current C++ version we are using (without adding a new library dependency edit: actually I guess we could use vtksys, but the second point still applies), and in any case, doing so without warning might be unwelcome in some circumstances.