当前位置: 首页>>代码示例>>C++>>正文


C++ MoveFileEx函数代码示例

本文整理汇总了C++中MoveFileEx函数的典型用法代码示例。如果您正苦于以下问题:C++ MoveFileEx函数的具体用法?C++ MoveFileEx怎么用?C++ MoveFileEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MoveFileEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MoveDirectory

// 将pc中的文件夹从一个目录拷贝到另外的一个目录
BOOL MoveDirectory(CString strSrcPath, CString strDesPath)
{
	if( strSrcPath.IsEmpty() )
	{       
		return FALSE;
	}

	if ( !PathIsDirectory(strDesPath) )
	{
		if ( !CreateDirectory(strDesPath,NULL))
			return FALSE;
	}

	if ( strSrcPath.GetAt(strSrcPath.GetLength()-1) != '\\' )
		strSrcPath += '\\';
	if ( strDesPath.GetAt(strDesPath.GetLength()-1) != '\\' )
		strDesPath += '\\';

	BOOL bRet = FALSE; // 因为源目录不可能为空,所以该值一定会被修改
	CFileFind ff;  
	BOOL bFound = ff.FindFile(strSrcPath+_T("*"),   0);  
	CString strFile;
	BOOL bSpecialFile=FALSE;
	while(bFound)      // 递归拷贝
	{  
		bFound = ff.FindNextFile();  
		bSpecialFile=FALSE;
		if( ff.IsDots() )  
			continue;

		CString strSubSrcPath = ff.GetFilePath();
		CString strSubDespath = strSubSrcPath;
		strSubDespath.Replace(strSrcPath, strDesPath);

		if( ff.IsDirectory() )
			bRet = MoveDirectory(strSubSrcPath, strSubDespath);     // 递归拷贝文件夹
		else
		{
			strFile=PathFindFileName(strSubSrcPath);
			strFile.MakeUpper();
			for (int i=0;i<nSpecialFileCount;i++)
			{
				//找到特殊文件
				if(_tcscmp(strFile.GetString(),sSpecialFile[i])==0)
				{
					bSpecialFile=TRUE;
					break;
				}	
			}
			if(bSpecialFile)
				bRet=MoveFileEx( strSubSrcPath,strSubDespath,MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
			else
				bRet = MoveFileEx(strSubSrcPath, strSubDespath,MOVEFILE_REPLACE_EXISTING);   // 移动文件
		}
		if ( !bRet )
			break;
	}  
	ff.Close();
	return bRet;
}
开发者ID:isnb,项目名称:AutoUpdate,代码行数:61,代码来源:PatchDlg.cpp

示例2: move_program

static BOOL move_program() {
    if (MoveFileEx(L"Calibre Portable\\calibre-portable.exe", 
                L"..\\calibre-portable.exe", MOVEFILE_REPLACE_EXISTING) == 0) {
        show_last_error(L"Failed to move calibre-portable.exe, make sure calibre is not running");
        return false;
    }

    if (directory_exists(L"..\\Calibre")) {
        if (!rmtree(L"..\\Calibre")) {
            show_error(L"Failed to delete the Calibre program folder. Make sure calibre is not running.");
            return false;
        }
    }

    if (MoveFileEx(L"Calibre Portable\\Calibre", L"..\\Calibre", 0) == 0) {
        Sleep(4000); // Sleep and try again
        if (MoveFileEx(L"Calibre Portable\\Calibre", L"..\\Calibre", 0) == 0) {
            show_last_error(L"Failed to move calibre program folder. This is usually caused by an antivirus program or a file sync program like DropBox. Turn them off temporarily and try again. Underlying error: ");
            return false;
        }
    }

    if (!directory_exists(L"..\\Calibre Library")) {
        MoveFileEx(L"Calibre Portable\\Calibre Library", L"..\\Calibre Library", 0);
    }

    if (!directory_exists(L"..\\Calibre Settings")) {
        MoveFileEx(L"Calibre Portable\\Calibre Settings", L"..\\Calibre Settings", 0);
    }

    return true;
}
开发者ID:Aliminator666,项目名称:calibre,代码行数:32,代码来源:portable-installer.cpp

示例3: RemoveDirectory

BOOL install_util::DeleteFolder(LPCTSTR pszFolder)
{
  if(IsFolderEmpty(pszFolder))
    return RemoveDirectory(pszFolder);

  //下面的实现据说有隐患。应改为递归删除所有子文件及文件夹
  _TCHAR szPath[MAX_PATH + 1] = {0};
  _sntprintf_s(szPath, _countof(szPath), sizeof(szPath), _TEXT("%s%c"), pszFolder, 0);

  SHFILEOPSTRUCT fos ;
  ZeroMemory(&fos, sizeof( fos)) ;
  fos.hwnd = HWND_DESKTOP;
  fos.wFunc = FO_DELETE ;
  fos.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
  fos.pFrom = szPath;

  // 删除文件夹及其内容
  if (0 == SHFileOperation(&fos))
    return TRUE;

  wstring tmpFile = szPath;
  tmpFile += L"_yytmp";
  if (MoveFileEx(szPath, tmpFile.c_str(), MOVEFILE_REPLACE_EXISTING))
    return MoveFileEx(tmpFile.c_str(),NULL,MOVEFILE_DELAY_UNTIL_REBOOT);

  return FALSE;
} 
开发者ID:510908220,项目名称:setup,代码行数:27,代码来源:install_util.cpp

示例4: DeleteFile

BOOL DeleteFile(LPCTSTR lpszFileName, DWORD dwPlatformID)
{
	// Delete file
	if (!::DeleteFile(lpszFileName))
	{
		if( VER_PLATFORM_WIN32_NT == dwPlatformID) //WINNT系列 
		{
			CString strTemp = lpszFileName;
			strTemp += _T(".tmp");
			//源文件文件改名成重新启动后自动删除
			//rename current file to file.tmp
			if(!MoveFileEx(lpszFileName, strTemp, MOVEFILE_REPLACE_EXISTING)
				|| !MoveFileEx(strTemp, NULL, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING))
				return FALSE;
		}
		else if (VER_PLATFORM_WIN32_WINDOWS == dwPlatformID) //win98
		{
			CString strOldFileName,strIniPathName;
			::GetWindowsDirectory(strIniPathName.GetBuffer(MAX_PATH),MAX_PATH);
			strIniPathName.ReleaseBuffer();
			strIniPathName += _T("\\wininit.ini");
			::GetShortPathName(lpszFileName,strOldFileName.GetBuffer(MAX_PATH),MAX_PATH);
			strOldFileName.ReleaseBuffer();
			if (!::WritePrivateProfileString(TEXT("rename"), _T("NUL"), strOldFileName,strIniPathName))
				return FALSE;
		}
	}
	return TRUE;
}
开发者ID:kaka-jeje,项目名称:zhu,代码行数:29,代码来源:opstr.cpp

示例5: SelfDelete

VOID SelfDelete(LPCSTR ModuleFileName)
{
	CHAR TempPath[MAX_PATH];
	CHAR TempName[MAX_PATH];

	GetTempPath(RTL_NUMBER_OF(TempPath)-1,TempPath);
	GetTempFileName(TempPath,NULL,0,TempName);

	MoveFileEx(ModuleFileName, TempName, MOVEFILE_REPLACE_EXISTING);
	MoveFileEx(TempName, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
}
开发者ID:AlexWMF,项目名称:Carberp,代码行数:11,代码来源:dropper.cpp

示例6: MoveFileEx

BOOL install_util::DeleteFile(LPCTSTR pszFile)
{
  if (::DeleteFile(pszFile))
    return TRUE;

  wstring tmpFile = pszFile;
  tmpFile += L"_yytmp";
  if (MoveFileEx(pszFile, tmpFile.c_str(), MOVEFILE_REPLACE_EXISTING))
    return MoveFileEx(tmpFile.c_str(),NULL,MOVEFILE_DELAY_UNTIL_REBOOT);

  return FALSE;
}
开发者ID:510908220,项目名称:setup,代码行数:12,代码来源:install_util.cpp

示例7: ConvertPath

//=============================================================================
// 函数名称:	移动覆盖一个指定的目录
// 作者说明:	mushuai
// 修改时间:	2013-03-14
//=============================================================================
int ConvertPath(LPCTSTR srcpath,LPCTSTR targpath)
{
	int iresult = 1;
	CFindFile finder;
	if(finder.FindFile(srcpath))
	{
		CString fileName,filePath;
		do
		{
			fileName=finder.GetFileName();
			filePath = finder.GetFilePath();
			//. ..
			if (finder.IsDots())
			{
				continue;
			}
			//dir
			else if (finder.IsDirectory())
			{
				CString tTargPath = targpath;
				tTargPath +=_T("\\")+fileName;
				ConvertPath(filePath+_T("\\*"),tTargPath);
				RemoveDirectory(filePath);
			}
			else//file
			{
				CString newFilePath = targpath;
				newFilePath +=_T("\\")+fileName;					
				if (!PathFileExists(targpath))
				{
					if(ERROR_SUCCESS != SHCreateDirectoryEx(0,targpath,0))
					{
						return 0;
					}
				}
				BOOL res=MoveFileEx(filePath,newFilePath,MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
				if (!res)
				{
					SetFileAttributes(newFilePath,FILE_ATTRIBUTE_NORMAL);
					if (!DeleteFile(newFilePath))
					{
						MoveFileEx(filePath,newFilePath,MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
					}
				}
			}
		}while (finder.FindNextFile());
	}
	finder.Close();
	return iresult;
}
开发者ID:ChenzhenqingCC,项目名称:WinProjects,代码行数:55,代码来源:publicfun.cpp

示例8: strcpy

//剪切一个文件夹到另外一个文件夹
bool TraverseFolder::CutfolderTofolder(LPCSTR path1,LPCSTR path2)
{
	WIN32_FIND_DATA findData;
	HANDLE hSearch;
	char FilePathName[MAX_PATH];
	char FullPathName1[MAX_PATH];
	char FullPathName2[MAX_PATH];
	strcpy(FilePathName,path1);
	strcat(FilePathName,"\\*.*");

	hSearch = FindFirstFile(FilePathName,&findData);
	if( hSearch ==INVALID_HANDLE_VALUE)
	{
		std::cout<<"Search files failed\n";
		return false;
	}
	while(::FindNextFile(hSearch,&findData))
	{
		if(strcmp(findData.cFileName,".") ==0||strcmp(findData.cFileName,"..") ==0)
		{
			continue;
		}
		sprintf(FullPathName1,"%s\\%s",path1,findData.cFileName);
		sprintf(FullPathName2,"%s\\%s",path2,findData.cFileName);

		if( !MoveFileEx(FullPathName1,FullPathName2,MOVEFILE_REPLACE_EXISTING))
		{
			std::cout<<"Move file"<<findData.cFileName<<"failed\n";
		}
	}
	::FindClose(hSearch);
	return true;
}
开发者ID:zhuangsifei,项目名称:planet_work,代码行数:34,代码来源:TraverseFolder.cpp

示例9: my_rename

int my_rename(const char *from, const char *to, myf MyFlags)
{
  int error = 0;
  DBUG_ENTER("my_rename");
  DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));

#if defined(HAVE_FILE_VERSIONS)
  {				/* Check that there isn't a old file */
    int save_errno;
    MY_STAT my_stat_result;
    save_errno=my_errno;
    if (my_stat(to,&my_stat_result,MYF(0)))
    {
      my_errno=EEXIST;
      error= -1;
      if (MyFlags & MY_FAE+MY_WME)
      {
        char errbuf[MYSYS_STRERROR_SIZE];
        my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG), from, to,
                 my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno));
      }
      DBUG_RETURN(error);
    }
    my_errno=save_errno;
  }
#endif
#if defined(__WIN__)
  if(!MoveFileEx(from, to, MOVEFILE_COPY_ALLOWED|
                           MOVEFILE_REPLACE_EXISTING))
  {
    my_osmaperr(GetLastError());
#else
  if (rename(from,to))
  {
#endif
    my_errno=errno;
    error = -1;
    if (MyFlags & (MY_FAE+MY_WME))
    {
      char errbuf[MYSYS_STRERROR_SIZE];
      my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG), from, to,
               my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno));
    }
  }
  else if (MyFlags & MY_SYNC_DIR)
  {
#ifdef NEED_EXPLICIT_SYNC_DIR
    /* do only the needed amount of syncs: */
    char dir_from[FN_REFLEN], dir_to[FN_REFLEN];
    size_t dir_from_length, dir_to_length;
    dirname_part(dir_from, from, &dir_from_length);
    dirname_part(dir_to, to, &dir_to_length);
    if (my_sync_dir(dir_from, MyFlags) ||
        (strcmp(dir_from, dir_to) &&
         my_sync_dir(dir_to, MyFlags)))
      error= -1;
#endif
  }
  DBUG_RETURN(error);
} /* my_rename */
开发者ID:Aisun,项目名称:SQLAdvisor,代码行数:60,代码来源:my_rename.c

示例10: MirrorMoveFile

static int DOKAN_CALLBACK
MirrorMoveFile(
	LPCWSTR				FileName, // existing file name
	LPCWSTR				NewFileName,
	BOOL				ReplaceIfExisting,
	PDOKAN_FILE_INFO	DokanFileInfo)
{
	WCHAR			filePath[MAX_PATH];
	WCHAR			newFilePath[MAX_PATH];
	BOOL			status;

	GetFilePath(filePath, MAX_PATH, FileName);
	GetFilePath(newFilePath, MAX_PATH, NewFileName);

	DbgPrint(L"MoveFile %s -> %s\n\n", filePath, newFilePath);

	if (DokanFileInfo->Context) {
		// should close? or rename at closing?
		CloseHandle((HANDLE)DokanFileInfo->Context);
		DokanFileInfo->Context = 0;
	}

	if (ReplaceIfExisting)
		status = MoveFileEx(filePath, newFilePath, MOVEFILE_REPLACE_EXISTING);
	else
		status = MoveFile(filePath, newFilePath);

	if (status == FALSE) {
		DWORD error = GetLastError();
		DbgPrint(L"\tMoveFile failed status = %d, code = %d\n", status, error);
		return -(int)error;
	} else {
		return 0;
	}
}
开发者ID:jdstroy,项目名称:dokany,代码行数:35,代码来源:mirror.c

示例11: IO_FileChannel__ChannelDesc_CloseAndRegister

void IO_FileChannel__ChannelDesc_CloseAndRegister(IO_FileChannel__Channel ch) {
  int res = close(ch->fd);
  
  if (res >= 0) {
    ch->fd = -1;
    IO__ChannelDesc_Close((IO__Channel)ch);
    
    if (ch->tmpIndex >= 0) {
      char* fname = (char*)OS_Path__Encode(ch->origName);
      char* tname = (char*)OS_Path__Encode((Object__String)ch->tmpName);
#ifdef __MINGW32__
        if (MoveFileEx(tname, fname, MOVEFILE_REPLACE_EXISTING) == 0)
          res = GetLastError();
        else
          res = 0;
#else
      res = rename(tname, fname);
#endif
      remove_tmp_file(ch);
    }
  }
  
  if (res < 0) {
    IO_StdChannels__IOError(ch->tmpIndex<0?(Object__String)ch->tmpName:ch->origName);
  }
}
开发者ID:AlexIljin,项目名称:oo2c,代码行数:26,代码来源:FileChannel.c

示例12: getFileSize

    void
    StdOutputRedirector::checkForFileWrapAround()  {
        if (_myMaximumFileSize > 0) {
            if (_myStartTime == -1) {
                _myStartTime = (long long)asl::Time().millis();
            }
            long long myDelta = asl::Time().millis() - _myStartTime;
            if (myDelta > (_myFileSizeCheckFrequInSec * 1000)) {
                long myCurrentSize = getFileSize(_myOutputFilename);
                if (myCurrentSize >= _myMaximumFileSize) {
                    _myOutputStreamOut.close();
                    // remove old archive
                    if (_myLogInOneFileFlag && _myRemoveOldArchiveFlag &&
                        _myOldArchiveFilename != "" &&  fileExists(_myOldArchiveFilename))
                    {
                        deleteFile(_myOldArchiveFilename);
                    }
                    // rename current log to archive version
                    string myNewFilename = removeExtension(_myOutputFilename) + "logarchive_" +
                                                           getCurrentTimeString() + (".log");
#ifdef _WIN32
                    MoveFileEx(_myOutputFilename.c_str(),
                               myNewFilename.c_str(),
                               MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
#else
                    rename(_myOutputFilename.c_str(), myNewFilename.c_str());
#endif
                    _myOldArchiveFilename = myNewFilename;
                    redirect();
                }
                _myStartTime = (long long)asl::Time().millis();
            }
        }
    }
开发者ID:artcom,项目名称:asl,代码行数:34,代码来源:StdOutputRedirector.cpp

示例13: CreateFile

VDLog* VDLog::get(TCHAR* path)
{
    if (_log || !path) {
        return _log;
    }
    DWORD size = 0;
    HANDLE file = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
                             NULL);
    if (file != INVALID_HANDLE_VALUE) {
        size = GetFileSize(file, NULL);
        CloseHandle(file);
    }
    if (size != INVALID_FILE_SIZE && size > LOG_ROLL_SIZE) {
        TCHAR roll_path[MAX_PATH];
        _sntprintf(roll_path, MAX_PATH, TEXT("%s.1"), path);
        if (!MoveFileEx(path, roll_path, MOVEFILE_REPLACE_EXISTING)) {
            return NULL;
        }
    }
    FILE* handle = _wfsopen(path, L"a+", _SH_DENYNO);
    if (!handle) {
        return NULL;
    }
    _log = new VDLog(handle);
    return _log;
}
开发者ID:freedesktop-unofficial-mirror,项目名称:spice__win32__usbclerk,代码行数:26,代码来源:vdlog.cpp

示例14: _tmain

int _tmain(int argc, _TCHAR* argv[]) {
    DWORD dw;
    LPVOID lpMsgBuf;
    int ret;

    if (argc != 2) {
        printf("Schedule a file or directory removal for the next reboot.\n");
        printf("Copyright 2008 Mandriva, Pulse 2 product, 27082008\n\n");
        printf("DELLATER <path/to/remove>\n");
        ret = 1;
    } else {
        if (MoveFileEx(argv[1], NULL, MOVEFILE_DELAY_UNTIL_REBOOT)) {
            ret = 0;
        } else {
            dw = GetLastError();
            FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                dw,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                (LPTSTR) &lpMsgBuf,
                0, NULL );
            printf("Failed with error %d: %s\n" , dw, lpMsgBuf);
            ret = 1;
        }
    }
    return ret;
}
开发者ID:AnatomicJC,项目名称:pulse2-secure-agent,代码行数:30,代码来源:dellater.cpp

示例15: memset

void CKernelManager::UnInstallService()
{
	char	key[1024], strServiceDll[MAX_PATH];
	memset(key, 0, sizeof(key));
	wsprintf(key, "SYSTEM\\CurrentControlSet\\Services\\%s", m_strServiceName);
	SHDeleteKey(HKEY_LOCAL_MACHINE, key);
	
	CreateEvent(NULL, true, false, m_strKillEvent);


	GetSystemDirectory(strServiceDll, sizeof(strServiceDll));
	lstrcat(strServiceDll, "\\");
	lstrcat(strServiceDll, m_strServiceName);
	lstrcat(strServiceDll, "ex.dll");
	MoveFileEx(strServiceDll, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);

	char	strIDFile[MAX_PATH];
	GetSystemDirectory(strIDFile, sizeof(strIDFile));
	lstrcat(strIDFile, "\\user.dat");
	DeleteFile(strIDFile);


	char	strRecordFile[MAX_PATH];
	GetSystemDirectory(strRecordFile, sizeof(strRecordFile));
	lstrcat(strRecordFile, "\\syslog.dat");
	DeleteFile(strRecordFile);
}
开发者ID:ShawnHuang,项目名称:footlocker,代码行数:27,代码来源:KernelManager.cpp


注:本文中的MoveFileEx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。