-
October 10th, 2009, 02:42 PM
#1
copying file from one location to another location
Hi,
I need to copy a file from one location say c:\a\abc.txt to c:\b\abc.txt. I used the following below code
#include <stdio.h>
#include<fstream>
int main()
{
if ( rename("c:\a\abc.txt","c:\b\abc.txt")
perror( NULL );
system("pause");
return 0;
}
when i ran this code, the original file in the folder "a" gets deleted. I do not want the original file to be deleted. what should i modify in this code so the original file remains undeleted.
and my next question is, i want to copy the original file 3 times and paste it in the new location 3 times, and each time while pasting i want the file name like this "abc1.txt", "abc2.txt", "abc3.txt"...and so on till i give a condition, so how to implement this?
Thanks
Priya
-
October 10th, 2009, 04:31 PM
#2
Re: copying file from one location to another location
Solution 1 (requires boost): Use copy_file() from the filesystem library.
Solution 2 (requires Windows API):Use CopyFile().
Solution 3: Use the C (fopen(), fread(), fwrite(), fclose()) or C++ (fstream:: open(), fstream::read(), fstream::write()) standard library to copy the contents of the input file to the output file. WARNING: This will not copy the file attributes or the alternate streams (for NTFS).
-
October 19th, 2009, 01:21 AM
#3
Re: copying file from one location to another location
Originally Posted by priya_esu
Hi,
I need to copy a file from one location say c:\a\abc.txt to c:\b\abc.txt. I used the following below code
#include <stdio.h>
#include<fstream>
int main()
{
if ( rename("c:\a\abc.txt","c:\b\abc.txt")
perror( NULL );
system("pause");
return 0;
}
when i ran this code, the original file in the folder "a" gets deleted. I do not want the original file to be deleted. what should i modify in this code so the original file remains undeleted.
and my next question is, i want to copy the original file 3 times and paste it in the new location 3 times, and each time while pasting i want the file name like this "abc1.txt", "abc2.txt", "abc3.txt"...and so on till i give a condition, so how to implement this?
Thanks
Priya
Look at ::SHFileOperation().
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|