Function to copy files in C++

C++ function to copy a file to another. Explained with it’s syntax, parameters, return value and an example

Syntax

Syntax of C++ function to copy file is
BOOL CopyFile(LPCTSTR ExistingFileName, LPCTSTR NewFileName, BOOL bFailIfExists);

Parameters

ExistingFileName
Enter the existing file path which is to be copied

NewFileName
Enter the new file path. This is the file where you will copy from existing file.

bFailIfExists
If you set this to TRUE – If NewFile already exists, copy operations fails
FALSE – If NewFile already exists, it will be overwritten

RETURN VALUE

Returns non-zero value if the function is successful
Returns Zero, if Fails

Example

returnValue = CopyFile(“C:\Temp\File1″, C:\Temp\File2”, TRUE);

Check C plus plus code to Extract/Replace String between two delimiters

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published.