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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2d7ec12dd7db366 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-27 20:54:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!isdnet!enst!enst.fr!not-for-mail From: "David Botton" Newsgroups: comp.lang.ada Subject: Re: How to rename a file? Date: Thu, 27 Sep 2001 23:41:32 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1001648526 21090 137.194.161.2 (28 Sep 2001 03:42:06 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 28 Sep 2001 03:42:06 +0000 (UTC) To: Return-Path: X-pair-Authenticated: 216.254.101.195 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:13454 Date: 2001-09-27T23:41:32-04:00 On Win32 if you wish to be cross compiler (this also demonstrates why thin bindings are mostly a waste of time for Ada): First the ugly method: function Rename_File (Old_File, New_File : String) return Boolean is Old_C : Interfaces.C.Char_Array := Interfaces.C.To_C (Old_File); New_C : Interfaces.C.Char_Array := Interfaces.C.To_C (New_File); function MoveFile (Old_Name : Interfaces.C.Char_Array := Old_C; New_Name : Interfaces.C.Char_Array := New_C) return Boolean; pragma Import (StdCall, MoveFile, "MoveFileA"); begin return MoveFile; end Rename_File; Now the cool method: function Rename_File2 (Old_File, New_File : String) return Boolean is function MoveFile (Old_Name : String := Old_File & Character'Val (0); New_Name : String := New_File & Character'Val (0)) return Boolean; pragma Import (StdCall, MoveFile, "MoveFileA"); begin return MoveFile; end Rename_File2; Ada arrays are passed as C arrays do to the import so the use of String is valid, we just need to Zero terminate. Ada record types are also passed as pointers, which makes life a lot easier. For many more examples look through the bodies of GWindows code http://www.adapower.com/gwindows BTW, if you don't care about the result: procedure Rename_File3 (Old_File, New_File : String) is procedure MoveFile (Old_Name : String := Old_File & Character'Val (0); New_Name : String := New_File & Character'Val (0)); pragma Import (StdCall, MoveFile, "MoveFileA"); begin MoveFile; end Rename_File3; If you are using a compiler other then GNAT, you may need to insure that WinBase.lib is linked in (as you would using a Win32 thin binding). David Botton ----- Original Message ----- From: "DuckE" Newsgroups: comp.lang.ada To: Sent: Thursday, September 27, 2001 10:16 PM Subject: Re: How to rename a file? > Here's how I make the OS call on WindowsNT/W2K using ObjectAda or GNAT: > > WITH Win32; > WITH Win32.WinBase; > WITH Interfaces.C; > ... > PACKAGE WinBase RENAMES Win32.WinBase; > PACKAGE C RENAMES Interfaces.C; > > USE TYPE Win32.BOOL; > USE TYPE Win32.DWORD; > ... > PROCEDURE RenameFileDFU( sourceFileNameDFU, destFileNameDFU : STRING; > renamedDFU : out BOOLEAN ) IS > result : Win32.BOOL; > sourceName : ALIASED C.Char_Array := C.To_C( sourceFileNameDFU ); > destName : ALIASED C.Char_Array := C.To_C( destFileNameDFU ); > BEGIN > result := WinBase.MoveFile( sourceName(0)'UNCHECKED_ACCESS, > destName(0)'UNCHECKED_ACCESS ); > renamedDFU := result /= Win32.FALSE; > END RenameFileDFU; > > I hope this helps, > SteveD > > "Pi" wrote in message > news:MYKs7.11405$%r.2963162@news20.bellglobal.com... > > It may sound stupid, but I didn't find anything. > > > > Is there a way to rename files in Ada? > > > > Other than : > > create a new file, > > copy every byte into the new one, > > delete the old one. > > > > -- > > 3,14159265359 > > > > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada >