1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <stdio.h>
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#define chunk (5*1024)
void copy_folder(char *src, char *dest)
{
WIN32_FIND_DATA info ;
HANDLE hwnd ;
char temp[1000] = "" ;
char temp_1[1000] = "" ;
char temp_src[1000] ;
char temp_dest[1000] ;
int in, out, i, x ;
void *buffer ;
strcpy(temp_1, src) ;
strcat(temp_1, "\\*.*") ;
//SECURITY_ATTRIBUTES s ;
CreateDirectory(dest,NULL) ;
hwnd = FindFirstFile(temp_1, &info) ;
do{
if (!strcmp(info.cFileName , ".")) continue ;
if (!strcmp(info.cFileName , "..")) continue ;
strcpy(temp_src, src) ;
strcat(temp_src, "\\") ;
strcat(temp_src, info.cFileName) ;
if (info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
strcpy(temp_dest, dest) ;
strcat(temp_dest, "\\") ;
strcat(temp_dest, info.cFileName) ;
//CreateDirectory(temp_dest, NULL) ;
copy_folder(temp_src, temp_dest) ;
}else{
strcpy(temp, dest) ;
strcat(temp, "\\") ;
strcat(temp, info.cFileName) ;
printf("%s\n", temp) ;
//copy_file(temp_src, temp)
buffer = malloc(chunk) ;
in = (int)open(temp_src, O_RDONLY|O_BINARY) ;
out = (int)(temp, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC) ;
printf("%s %s\n", temp_src, temp) ;
while (i = read(in, buffer, chunk)){
//printf("%s\n", buffer) ;
x = write(out, buffer, i) ;
//printf("%d %d\n", x, i) ;
}
close(in) ;
close(out) ;
free(buffer) ;
}
}while (FindNextFile(hwnd, &info)) ;
FindClose(hwnd) ;
}
int main()
{
char src[1000] = "D:\\Utility" ;
char dest[1000] = "E:\\U" ;
copy_folder(src, dest) ;
return 0 ;
}
|