c - 如何写入目录C
问题描述
我正在尝试将目录内容复制到另一个目录,但是在不使用sprintf
;的情况下写入第二个目录时遇到问题 有什么建议么?
void Copying(char *folder1, char *folder2) {
DIR *s1, *s2;
struct dirent *dep;
if ((s1 = opendir(folder1)) == NULL) {
printf("Error\n");
return;
}
if ((s2 = opendir(folder2)) == NULL) {
printf("Error \n");
return;
}
while ((dep = readdir(s1)) != NULL) {
//write(s2 , dep->d_name , sizeof(dep) ) ; // <-
}
closedir(s1);
closedir(s2);
return;
}
解决方案
这种方法行不通。目录句柄不可写。
如果要复制目录的内容,则需要分别复制源目录中的每个文件、目录和链接。要复制每个文件,您需要在目标目录中创建一个新文件并将源文件的内容写入其中。
推荐阅读
- python - 使用两个索引值pandas将一列的逗号分隔的字符转换为多行
- chart.js - chart js条形图添加动画改变颜色
- laravel-5 - laravel 更新时的唯一字段验证规则
- adobe-indesign - 无法通过 ExtendScript 读取 InDesign XMP 文件并写入外部 xml
- ios - 如何从 WKWebview 内的按钮单击重定向并使用目标 c 返回到 iOS 应用程序?
- dialogflow-es - Dialogflow Google Assistant Alpha Release For en:您的示例发音结构不正确
- c# - 如何在 C# 中更改用户给定日期的值
- javascript - Node.js 使用循环批量创建文件到当前目录中的每个文件夹
- php - 如何将 DATE 添加到学说查询?
- plsql - Oracle Apex 选择列表 LOV 条件查询