Why are my attempts to open a file using open for writing failing?

ada, file-io

Solution

If the "file does not exist," you should `Create` it first, for example. Note that "For text input-output, the procedures `Create`, `Open`, and `Reset` have additional effects described in subclause A.10.2."

If this is related to your previous question, it may help to provide more details.

Problem

When I attempt to open a file to write, I get an error: `Ada.IO_Exceptions.Name_Error`. The procedure call is `Ada.Text_IO.Open`; the file name is `C:\CC_TEST_LOG.TXT`. This file does not exist. This is on Windows XP on an NTFS partition. The user has permissions to create and write to the directory. The filename is well under the WIN32 max path length. ``` name_2 : String := "C:\CC_TEST_LOG.TXT" if name_2'last > name_2'first then begin Ada.Text_IO.Open(file, Ada.Text_IO.Out_File, name_2); Ada.Text_IO.Put_Line( "CC_Test_Utils: LogFile: ERROR: Open, File " & name_2); return; exception when The_Error : others => Ada.Text_IO.Put_Line( "CC_Test_Utils: LogFile: ERROR: Open Failed; " & Ada.Exceptions.Exception_Name(The_Error) & ", File " & name_2); end; end if; ```

Original source