|
// BackupFile.h Version 1.0
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like, except
// that you may not sell this source code.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BackupFile.h"
#include <io.h>
BOOL BackupFile(LPCTSTR lpszFile)
{
ASSERT(lpszFile);
// if file doesn't exist, nothing to do
if (_taccess(lpszFile, 00) == -1)
return TRUE;
// file exists, so make a backup copy
CString strFileRoot = lpszFile;
CString strPath = _T("");
CString strExt = _T("");
BOOL bSuccess = FALSE;
for (int i = 1; i <= 9999; i++)
{
strExt.Format(_T(".%04d"), i);
strPath = strFileRoot;
strPath += strExt;
if (_taccess(strPath, 00) == -1)
{
// file doesn't exist, so we can use it
bSuccess = CopyFile(lpszFile, strPath, TRUE);
break;
}
}
return bSuccess;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
Recently, I have moved to Los Angeles where I am doing consulting and development work.
For consulting and custom software development, please see
www.hdsoft.org.