From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c71bf3c5adc59b21,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!k7g2000hsd.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Opening a file vs. creating if not yet exists Date: Mon, 18 Aug 2008 08:03:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 128.141.45.203 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1219071810 14786 127.0.0.1 (18 Aug 2008 15:03:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 18 Aug 2008 15:03:30 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k7g2000hsd.googlegroups.com; posting-host=128.141.45.203; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1644 Date: 2008-08-18T08:03:29-07:00 List-Id: Hi, The Open procedure for opening files expects the given external file to already exist (otherwise the Name_Error is signalled). The Create procedure truncates the file no matter what, even if the mode for opening a file is Append_File. I find this a bit annoying for example with log files, where the natural scheme should be: - if the file exists, open and append to it - if the file does not exist, create it and append to it What is the recommended way to deal with this? begin Open (File, Append_File, "file.txt"); exception when Name_Error => Create (File, Append_File, "file.txt"); end; Is the above idiomatic (ie. well understood and accepted as common practice)? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada