diff --git a/src/demo/platform/file.c b/src/demo/platform/file.c index 21c2725bc..ad407d500 100644 --- a/src/demo/platform/file.c +++ b/src/demo/platform/file.c @@ -198,7 +198,7 @@ tb_int_t tb_demo_platform_file_main(tb_int_t argc, tb_char_t** argv) // exit file if (ifile) tb_file_exit(ifile); if (ofile) tb_file_exit(ofile); -#elif 0 +#elif 1 tb_bool_t ok = tb_file_rename(argv[1], argv[2]); tb_trace_i("rename: %s => %s %s", argv[1], argv[2], ok? "ok" : "failed"); #elif 1 diff --git a/src/tbox/platform/windows/file.c b/src/tbox/platform/windows/file.c index 90bdc1940..6d00ab45d 100644 --- a/src/tbox/platform/windows/file.c +++ b/src/tbox/platform/windows/file.c @@ -492,16 +492,15 @@ tb_bool_t tb_file_rename(tb_char_t const* path, tb_char_t const* dest) if (!tb_path_absolute_w(dest, full1, TB_PATH_MAXN)) return tb_false; // rename it - if (!MoveFileExW(full0, full1, MOVEFILE_REPLACE_EXISTING)) + DWORD flags = MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH; + if (!MoveFileExW(full0, full1, flags)) { // make directory tb_file_mkdir(full1); // rename it again - return MoveFileExW(full0, full1, MOVEFILE_REPLACE_EXISTING); + return MoveFileExW(full0, full1, flags); } - - // ok return tb_true; } tb_bool_t tb_file_link(tb_char_t const* path, tb_char_t const* dest)