📄 xcopy.c
字号:
/*
* Copyright (c) 2000-2008
* Author: Weiming Zhou
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*/
#include <windows.h>
#include <stdio.h>
void CopyCurrentDir( char *pszSrcDir, char *pszTargeDir, BOOL bOverWrite );
/** 将一个目录及子目录下的所有文件复制到另外一个目录下
@param char *pszSrcDir - 要拷贝的源目录
@param char *pszTargeDir - 目标目录
@param BOOL bOverWrite - 覆盖标志,FALSE表示覆盖
@return void - 无
*/
void Xcopy( char *pszSrcDir, char *pszTargeDir, BOOL bOverWrite )
{
char szBaseSearch[MAX_PATH];
char szCurrentPath[MAX_PATH];
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
memset( szCurrentPath, 0, MAX_PATH );
GetCurrentDirectory( MAX_PATH, szCurrentPath );
sprintf( szBaseSearch, "%s\\*.*", szCurrentPath );
hFindFile = FindFirstFile( szBaseSearch, &FindData );
if ( hFindFile == INVALID_HANDLE_VALUE ) {
return;
}
do {
CreateDirectory( pszTargeDir, NULL );
if ( !strcmp( FindData.cFileName, "." ) ||
!strcmp( FindData.cFileName, ".." )) {
// skip . and ..
continue;
}
if ( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
// a directory
char szBaseDir[MAX_PATH];
char szTargeDir[MAX_PATH];
sprintf( szBaseDir, "%s\\%s", szCurrentPath, FindData.cFileName );
SetCurrentDirectory( szBaseDir );
_fullpath( szTargeDir, pszTargeDir, MAX_PATH );
sprintf( szTargeDir, "%s\\%s", FindData.cFileName );
Xcopy( szBaseDir, szTargeDir, bOverWrite );
SetCurrentDirectory( szCurrentPath );
}
} while ( FindNextFile( hFindFile, &FindData ));
FindClose( hFindFile );
CopyCurrentDir( pszSrcDir, pszTargeDir, bOverWrite );
}
/** 将一个目录下的所有文件拷贝到另外一个目录下
@param char *pszSrcFile - 要拷贝的目录
@param char *pszTargeFile - 目标文件或目录
@param BOOL bOverWrite - 是否覆盖的标志,为FALSE表示覆盖掉原有文件
@return void - 无
*/
void CopyCurrentDir( char *pszSrcDir, char *pszTargeDir, BOOL bOverWrite )
{
char szBaseSearch[MAX_PATH];
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
sprintf( szBaseSearch, "%s", pszSrcDir );
hFindFile = FindFirstFile( szBaseSearch, &FindData );
if ( hFindFile == INVALID_HANDLE_VALUE ) {
return;
}
do {
CreateDirectory( pszTargeDir, NULL );
if ( !strcmp( FindData.cFileName, "." ) ||
!strcmp( FindData.cFileName, ".." )) {
// skip . and ..
continue;
}
if ( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
// a directory
continue;
}
else {
// plain file
char szSrcDir[MAX_PATH];
char szTargeDir[MAX_PATH];
sprintf( szSrcDir, "%s", FindData.cFileName );
sprintf( szTargeDir, "%s\\%s", pszTargeDir, FindData.cFileName );
CopyFile( szSrcDir, szTargeDir, bOverWrite );
}
} while ( FindNextFile( hFindFile, &FindData ));
FindClose( hFindFile );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -