From: Zhenbo Li Subject: [PATCH] shell32: Fix SHFileOperation(FO_MOVE) for creating subdirectories. Message-Id: <55CDEAB3.7030108@gmail.com> Date: Fri, 14 Aug 2015 21:18:43 +0800 This patch fixes bug 25207. Seems that a dozen of apps are affected by this bug, so please tell me how I can improve this patch if this patch can't be committed directly. There will be a test error: shlfileop.c:818: Test failed: Expected ERROR_CANCELLED or DE_DIFFDIR It is not related to my patch. Hope you enjoy your weekend. --- dlls/shell32/shlfileop.c | 11 +++++++++-- dlls/shell32/tests/shlfileop.c | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dlls/shell32/shlfileop.c b/dlls/shell32/shlfileop.c index 0b096b1..3ff3c20 100644 --- a/dlls/shell32/shlfileop.c +++ b/dlls/shell32/shlfileop.c @@ -1401,7 +1401,7 @@ static void move_to_dir(LPSHFILEOPSTRUCTW lpFileOp, const FILE_ENTRY *feFrom, co /* the FO_MOVE operation */ static DWORD move_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom, const FILE_LIST *flTo) { - DWORD i; + DWORD i, ret; INT mismatched = 0; const FILE_ENTRY *entryToMove; const FILE_ENTRY *fileDest; @@ -1426,7 +1426,14 @@ static DWORD move_files(LPSHFILEOPSTRUCTW lpFileOp, const FILE_LIST *flFrom, con } if (!PathFileExistsW(flTo->feFiles[0].szDirectory)) - return ERROR_CANCELLED; + { + ret = SHCreateDirectoryExW(NULL, flTo->feFiles[0].szDirectory, NULL); + if(ret) + { + ERR("SHCreateDirectoryW failed: %08x\n", ret); + return ret; + } + } if (lpFileOp->fFlags & FOF_MULTIDESTFILES) mismatched = flFrom->dwNumFiles - flTo->dwNumFiles; diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c index d33ad5b..b303073 100644 --- a/dlls/shell32/tests/shlfileop.c +++ b/dlls/shell32/tests/shlfileop.c @@ -2205,13 +2205,13 @@ static void test_move(void) ok(!DeleteFileA("d.txt"), "Expected d.txt to not exist\n"); } - /* FO_MOVE does not create dest directories */ + /* FO_MOVE should create dest directories */ shfo.pFrom = "test2.txt\0"; shfo.pTo = "dir1\\dir2\\test2.txt\0"; retval = SHFileOperationA(&shfo); if (dir_exists("dir1")) { - /* Vista and W2K8 (broken or new behavior ?) */ + /* New behavior on Vista or later */ ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval); ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n"); RemoveDirectoryA("dir1\\dir2"); @@ -2220,7 +2220,7 @@ static void test_move(void) } else { - expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */); + win_skip("Behavior on XP or before\n"); } /* try to overwrite an existing file */