windows - C++ - The wrong volume is in the drive - Catch error -
i'm trying copy files external drive via buffered reader in c++. works. if unplug hard disk, "the wrong volume in drive" error appears. possible catch error , log myself "error - drive disconnected"? tried seterrormode(seterrormode(0) | sem_nogpfaulterrorbox);
far doesn't work.
here's script copy folder:
void copy_folder(char *src, char *dest) { try{ 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) open (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) ; }catch(...){ //const char* msg ) {log << "error - drive disconnected" << endl;copy_error = true;} }
Comments
Post a Comment