我一直在試圖製作一個程序,通過網絡複製文件,以在我的電腦和筆記本電腦之間同步遊戲保存,只要其中一個更新。問題是,當我運行該程序時,它只是保持「複製」,永遠不會結束。但是,如果我在同一臺電腦上使用完全相同的文件,它會立即執行此操作,但我也嘗試通過網絡發送一個txt文件,它工作得很好。有任何想法嗎?這裏是我的代碼:通過網絡複製文件C++
void copyFile() {
char x;
path PC = "C:\\Users\\Luciano\\Documents\\Sports Interactive\\Football Manager Touch 2017\\games\\River.fmt";
path Notebook = "Z:\\games\\River.fmt";
std::time_t lastWriteTo=0, lastWriteFrom=0;
if(exists(PC)){lastWriteFrom = last_write_time(PC);}
if(exists(Notebook)){lastWriteTo = last_write_time(Notebook);}
if (lastWriteFrom > lastWriteTo || !exists(Notebook)) {
std::cout << "Hay que copiar de la PC a la notebook" << std::endl;
std::cout << "Copiar Archivo? Este es de :" << (file_size(PC)/1024)/1024 << " Mb (S/N)" << std::endl;
std::cin >> x;
switch (x) {
case 'S':
std::cout << "Copiando Archivo..." << std::endl;
try {
copy_file(PC, Notebook, copy_option::overwrite_if_exists);
}
catch (filesystem_error &e) {
std::cerr << e.what() << '\n';
}
break;
case 's':
std::cout << "Copiando Archivo..." << std::endl;
try {
copy_file(PC, Notebook, copy_option::overwrite_if_exists);
}
catch (filesystem_error &e) {
std::cerr << e.what() << '\n';
}
break;
default:
std::cout << "Se ha cancelado la copia del archivo" << std::endl;
break;
}
}
else if(lastWriteFrom < lastWriteTo || !exists(PC)){
std::cout << "Hay que copiar de la notebook a la PC" << std::endl;
std::cout << "Copiar Archivo? Este es de :"<< (file_size(PC)/1024)/1024 <<"(S/N)" << std::endl;
std::cin >> x;
switch (x) {
case 'S':
std::cout << "Copiando Archivo..." << std::endl;
try {
copy_file(Notebook, PC, copy_option::overwrite_if_exists);
}
catch (filesystem_error &e) {
std::cerr << e.what() << '\n';
}
break;
case 's':
std::cout << "Copiando Archivo..." << std::endl;
try {
copy_file(Notebook, PC, copy_option::overwrite_if_exists);
}
catch (filesystem_error &e) {
std::cerr << e.what() << '\n';
}
break;
default:
std::cout << "Se ha cancelado la copia del archivo" << std::endl;
break;
}
}else {
std::cout << "No es necesario la copia del archivo." << std::endl;
}
}
也許問題是在copy_file函數? – Saustin
@Saustin不知道,但我認爲這可能是std :: experimental :: filesystem。 – Robinson