Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!hunt From: hunt@dg-rtp.rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.questions Subject: Re: mv'ing files from a C program Message-ID: <1990Nov16.180137.29649@dg-rtp.dg.com> Date: 16 Nov 90 18:01:37 GMT References: <22@mixcom.UUCP> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hunt@dg-rtp.rtp.dg.com Distribution: na Organization: Data General Corp., Research Triangle Park, NC Lines: 26 In article <22@mixcom.UUCP>, ggvvgg@mixcom.UUCP (Dave Fenske) writes: > Is there an easy way to do an 'mv' from a C program? > > I just want to be able to move a recently read file into another directory, > and wish to avoid having to write it there. Using the 'system' call is > not deemed wiable for this application. > You can use the 'rename' system call to do what you want. Do something like the following: status = rename ("/udd/olddir/myfile", "/udd/newdir/myfile"); If the new pathname and the old pathname are on the same file systems, everything will work just fine. If they are on different file systems, it may or may not work depending on what your OS permits. If it's not allowed, then you'll have to copy the file to the new location (which is what 'mv' would have to do in that case). See the man page for 'rename' for more details. Enjoy! -- Greg Hunt Internet: hunt@dg-rtp.rtp.dg.com DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt Data General Corporation Research Triangle Park, NC These opinions are mine, not DG's.