如果copyTo和copyFrom目录相同,则SHFileOperation不起作用-这是一个错误吗? [英] SHFileOperation doesn't work if copyTo and copyFrom directories are the same - is this a bug?

查看:138
本文介绍了如果copyTo和copyFrom目录相同,则SHFileOperation不起作用-这是一个错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SHFileOperation将目录复制到自身中

例如将文件夹C:\ folder1 \ folder2复制到C:\ folder1 \ folder2,以C:\ folder1 \ folder2 \ folder2结尾.

folder2包含文件和文件夹.

这是唯一无法使SHFileOperation正常工作的情况.

为了解决这个问题,我尝试首先创建一个新目录:

I am trying to use SHFileOperation to copy a directory into itself

e.g. copy the folder C:\folder1\folder2 into C:\folder1\folder2 to end up with C:\folder1\folder2\folder2.

folder2 contains file and folders.

This is the only case which I cannot get SHFileOperation to work.

In order to get round this problem, I tried creating a new directory first:

CreateDirectory("C:\folder1\folder2\folder2", NULL);


然后将"C:\ folder1 \ folder2 \ *"复制到"C:\ folder1 \ folder2 \ folder2"

这样就创建了新目录,并将所有文件从C:\ folder1 \ folder2复制到C:\ folder1 \ folder2 \ folder2,但是没有复制任何目录(我没有设置停止递归的标志).

有没有其他人遇到这个问题,或者知道一个解决方法?否则,我将不得不编写自己的递归方法:(..


and then copying "C:\folder1\folder2\*" to "C:\folder1\folder2\folder2"

This created the new directory and copied any files from C:\folder1\folder2 into C:\folder1\folder2\folder2 but it did not copy any directories (I do not have the flag set to stop recursion).

Has anyone else had this problem, or know a way round it? Otherwise I will have to write my own recursive method :(.

推荐答案

复制到临时目录,然后将其移动到目标目录.
Copy to a temporary directory and then move that to the destination.


msdn说:
msdn says:
pFrom
    
        Type: LPCTSTR
    
        Note  This string must be double-null terminated.
    
        A pointer to one or more source file names. These names should be fully-qualified paths to prevent unexpected results.
    
        Standard MS-DOS wildcard characters, such as "*", are permitted only in the file-name position. Using a wildcard character elsewhere in the string will lead to unpredictable results.
    
        Although this member is declared as a single null-terminated string, it is actually a buffer that can hold multiple null-delimited file names. Each file name is terminated by a single NULL character. The last file name is terminated with a double NULL character ("\0\0") to indicate the end of the buffer.


(来自 http://msdn.microsoft.com/zh-cn/library/windows/desktop/bb759795%28v = vs.85%29.aspx [ lpszFromDir +"\\ *.*" .您可以使用::PathCombine() API附加通配符.

希望对您有所帮助,


(from http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795%28v=vs.85%29.aspx[^])
In other words, your pFrom parameter should be lpszFromDir + "\\*.*". You can use the ::PathCombine() API to append the wildcard.

Hope this helps,


这篇关于如果copyTo和copyFrom目录相同,则SHFileOperation不起作用-这是一个错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆