Copy and Delete files in c++

imported_tamim

Junior Member
Feb 22, 2006
8
0
0
what is the easiest way to copy (i.e. duplicate) and delete files (txt lets say) in c++?

I'm looking in a book called C++ How To Program by Deitel....cant find a way to delete files. Thanks.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
CopyFile
The CopyFile function copies an existing file to a new file.

BOOL CopyFile(
LPCTSTR lpExistingFileName,
// pointer to name of an existing file

LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);

Parameters
lpExistingFileName
Pointer to a null-terminated string that specifies the name of an existing file.

lpNewFileName
Pointer to a null-terminated string that specifies the name of the new file.

bFailIfExists
Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.


Return Values
If the function succeeds, the return value is nonzero.
DeleteFile
The DeleteFile function deletes an existing file.

BOOL DeleteFile(
LPCTSTR lpFileName // pointer to name of file to delete
);

Parameters
lpFileName
Pointer to a null-terminated string that specifies the file to be deleted.

Return Values
If the function succeeds, the return value is nonzero.
[/q