简体   繁体   English

数据工厂 | 从多个子文件夹递归复制到一个同名文件夹

[英]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 所有数据集都选择为二进制

  1. GET METADATA - CHILDITEMS获取元数据 - CHILDITEMS
  2. FOR EACH - Childitem FOR EACH - 子项目
  3. COPY ACTIVITY(RECURSIVE: TRUE, COPY BEHAVIOUR: FLATTEN)复制活动(递归:真,复制行为:展平)

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方法二

  1. GET METADATA - CHILDITEMS获取元数据 - CHILDITEMS
  2. FOR EACH - Childitems FOR EACH - 子项目
  3. Execute PL2 (Pipeline level parameter: @item.name)执行PL2(流水线级参数:@item.name)
  4. Get Metadata2 (Parameterised from dataset, invoked at pipeline level)获取 Metadata2(从数据集中参数化,在管道级别调用)
  5. For EACH2- Childitems对于 EACH2- 子项目
  6. Copy (Source: FolderName - Pipeline level, File name - ForEach2)复制(来源:FolderName - 管道级别,文件名 - ForEach2)

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.

相关问题 如何使用数据工厂将多个 csv 文件从 blob 批量复制到多个 sql 数据库表 - How to bulk copy multiple csv files from blob to mutliple sql database tables with data factory 将多个 csv 文件中的数据复制到一个 csv 文件中 - Copy data from multiple csv files into one csv file 使用Data Factory复制文件时如何在Blob存储中保持文件夹结构 - How to keep folder structure in blob storage when using Data Factory to copy file Azure 数据工厂根据大小从文件夹中抓取文件 - Azure Data Factory grab file from folder based on size 将最新的文件夹从 azure blob 存储加载到 azure 数据工厂 - Load the latest folder from azure blob storage to azure data factory 我们可以使用 Azure 数据工厂将.BAK(SQL Server 备份文件)文件从本地服务器文件夹复制到 Azure Blob 存储吗? - Can we copy .BAK(SQL Server Backup Files) files from on-premise server file folder to Azure Blob Storage using Azure Data Factory? AzCopy - 如何从 root$ 开始递归地将所有 blob 从一个存储帐户复制到另一个存储帐户 - AzCopy - how to copy ALL blobs from one storage account to another recursively starting from root$ 有没有办法通过 Azure 数据工厂将增量数据从 SQL Server 复制到 Blob 存储? - Is there any way to copy incremental data from SQL Server to Blob Storage Through Azure Data Factory? 将数据从Azure Blob存储复制到Prem共享文件夹TFS上 - Copy data from Azure blob storage to on Prem shared folder TFS 使用 Azure 数据工厂将数据 (.csv) 从 Sql 服务器复制到 Azure Blob 存储 (ADLS2) - Copy data(.csv) from Sql server to Azure Blob Storage(ADLS2) using Azure Data Factory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM