Operating System - HP-UX
1829585 Members
2080 Online
109992 Solutions
New Discussion

moving file across file system

 
Ramprasath_1
Occasional Advisor

moving file across file system

I want to move file from one file system to another using my C++ code.Link() function fails to do so.Sice i have to delete the file from its source after moving so symlink() is also of no use.copy and unlink is of no use to me as i want that if file is already present in destination directory then it should not be overwritten.Is there any other function in C++ that moves files from one file system to other on unix platform without overwriting it if it already exists in destination? Remember I am trying to move between different file systems.Please revert soon..
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: moving file across file system

Hi:

If I understand your question correctly, you must first test for the absence of the file in the destination directory and if absent, then copy the file from the source directory. Having copied the file, remove the original from the source directory.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: moving file across file system

There is really no built-in function to do this. If you are moving, copying, or linking files within C++ or C, you are expected to do all the tests and operations that "mv -i" , for example, would do for you.

Of course, one easy way to do this would be to build a shell script "on the fly" and then invoke the system() function that executes your script otherwise you will have to do tests and operations in low-level system calls that your small script would do implicitly.
If it ain't broke, I can fix that.
Peter Nikitka
Honored Contributor

Re: moving file across file system

Hi,

one possiblity is to use system() to use /usr/bin/cp to perform that task.

Otherwise I think you'll have to code it by yourself, e.g. using open(), read() and write().

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: moving file across file system

(It would be helpful if you had 2 or 1 spaces after each period.)

As Clay suggests, you either have to do all of that work, or invoke a script or system(3) to do that. You can even put an "if" in your system command string.