mv'ing files from a C program

Greg Hunt hunt at dg-rtp.rtp.dg.com
Sat Nov 17 05:01:37 AEST 1990


In article <22 at mixcom.UUCP>, ggvvgg at 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 at 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.



More information about the Comp.unix.questions mailing list