C / C ++复制具有自动递归文件夹/目录创建的文件

编程入门 行业动态 更新时间:2024-10-28 21:19:39
本文介绍了C / C ++复制具有自动递归文件夹/目录创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在Win32 API中,有 CopyFile 从字面上复制一个文件。但是,此API不会创建文件夹。例如,我想将 C:\ Data\output.txt 复制到 D:\ Temp \ Data \ output .TXT 。但是,目标文件夹 D:\ Temp 和 D:\ Temp \ Data 存在。在这种情况下,这个API只是失败。

是否有一个方便的API,可以自动递归地创建复制目录结构?当然,我可以做出这样的功能,但我希望有人已经做出了这个功能。 解决方案

SHFileOperation 应该诀窍。从MSDN:

复制和移动操作可以指定不存在的目标目录。在这种情况下,系统尝试创建它们,通常显示一个对话框,询问用户是否需要创建新的目录。要禁止这个对话框,并且静默地创建目录,请在中设置 FOF_NOCONFIRMMKDIR 标志fFlags 。

In Win32 API, there is CopyFile that literally copies a file. However, this API doesn't create folders. For example, I'd like to copy C:\Data\output.txt to D:\Temp\Data\output.txt. But, the target folders, D:\Temp and D:\Temp\Data', do not exist. In this case, this API just fails.

Is there a handy API that can automatically and recursively create directory structure on copy? Definitely, I can make such function, but I expect someone already made the function.

解决方案

SHFileOperation should do the trick. From MSDN:

Copy and Move operations can specify destination directories that do not exist. In those cases, the system attempts to create them and normally displays a dialog box to ask the user if they want to create the new directory. To suppress this dialog box and have the directories created silently, set the FOF_NOCONFIRMMKDIR flag in fFlags.

更多推荐

C / C ++复制具有自动递归文件夹/目录创建的文件

本文发布于:2023-10-09 09:22:00,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   文件夹   文件   目录

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!