[英]Data Factory | Copy recursively from multiple subfolders into one folder wit same name
Objective: Copy all files from multiple subfolders into one folder with same filenames.目标:将多个子文件夹中的所有文件复制到一个具有相同文件名的文件夹中。 Eg
例如
Source Root Folder
20221110/
AppID1
File1.csv
File2.csv
/AppID2
File3.csv
File4.csv
20221114
AppID3
File5.csv
File6.csv
and so on
Destination Root Folder
File1.csv
File2.csv
File3.csv
File4.csv
File5.csv
File6.csv
Approach 1 Azure Data Factory V2 All datasets selected as binary方法 1 Azure 数据工厂 V2 所有数据集都选择为二进制
This config renames the files with autogenerated names.此配置使用自动生成的名称重命名文件。 If I change the copy behaviour to preserve hierarchy, Both file name and folder structure remains intact.
如果我更改复制行为以保留层次结构,文件名和文件夹结构都保持不变。
Approach 2方法二
Both approaches not giving the desired output. Any help/Workaround would be appreciated.这两种方法都没有给出所需的 output。任何帮助/解决方法将不胜感激。
My understanding is in Option 2 Step 3 & 5:is done as to iterate through the folder and subfolder correct?我的理解是在选项 2 的第 3 步和第 5 步中:是否已完成遍历文件夹和子文件夹是否正确?
6. Copy (Source: FolderName - Pipeline level, File name - ForEach2) 6. 复制(来源:FolderName - 管道级别,文件名 - ForEach2)
I think since in step 6 you already have the filename.我想因为在第 6 步中你已经有了文件名。 On the SINK side, add an dynamic expression and add @Filename and that should do the trick.
在 SINK 端,添加一个动态表达式并添加 @Filename,这应该可以解决问题。
If all of your files are in the same directory level , you can try the below approach.如果您的所有文件都在同一目录级别,您可以尝试以下方法。
First use Get Meta data activity to get all files list and then use copy inside ForEach to copy to a target folder.首先使用 Get Meta 数据活动获取所有文件列表,然后使用 ForEach 内部的复制复制到目标文件夹。
These are my source files with directory structure:这些是我的目录结构的源文件:
Source dataset:源数据集:
Based on your directory level use the wildcard placeholder( */*
) in the source dataset.根据您的目录级别,在源数据集中使用通配符占位符 (
*/*
)。
The above error is only a warning, and we can ignore it while debug.上面的错误只是一个警告,我们调试的时候可以忽略它。
Get meta data activity:获取元数据活动:
This will give all the files list inside subfolders.这将给出子文件夹内的所有文件列表。
Give this array to a ForEach activity and inside ForEach use copy activity.将此数组提供给 ForEach 活动,并在 ForEach 内部使用复制活动。
Copy activity source:复制活动来源:
In the above also, the */*
should be same as we gave in Get Meta data.在上面,
*/*
应该与我们在获取元数据中提供的相同。
For sink dataset create a dataset parameter and use in the file path of dataset.对于接收器数据集,创建数据集参数并在数据集的文件路径中使用。
Copy activity sink:复制活动接收器:
Files copied to target folder:复制到目标文件夹的文件:
If your source files are not in same directory level then you can try the recursive approach mentioned in this article by @Richard Swinbank .如果您的源文件不在同一目录级别,那么您可以尝试@Richard Swinbank在这篇文章中提到的递归方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.