skip to Main Content

I need to Maintain Folder Structure to store files in yyyy/MM/DD format and I am getting date like this "2021-12-01T00:00:00Z" I need to Extract year from the date and to store in one variable and need to extract Month from date and set to another variable and for Date as well so that I will Concat these variable result under Copy activity Sink section

2

Answers


  1. Yes , you can Maintain Folder Structure by using Split .

    • First create parameter name and add value.
    • Create 3 set variable with year , month and date.

    enter image description here

    Inside Year,Month,Date. Add this dynamic content value :

    Year:@split(pipeline().parameters.fileName,'-')[0]
    enter image description here

    Month: @split(pipeline().parameters.fileName,'-')[1]

    Data:

    @split(split(pipeline().parameters.fileName,'-')[2],'T')[0]
    

    For more information refer this JSON Code representation.

    {
    
    "name": "pipeline1",
    
    "properties": {
    
    "activities": [
    
    {
    
    "name": "year",
    
    "type": "SetVariable",
    
    "dependsOn": [],
    
    "userProperties": [],
    
    "typeProperties": {
    
    "variableName": "year",
    
    "value": {
    
    "value": "@split(pipeline().parameters.fileName,'-')[0]",
    
    "type": "Expression"
    
    }
    
    }
    
    },
    
    {
    
    "name": "month",
    
    "type": "SetVariable",
    
    "dependsOn": [
    
    {
    
    "activity": "year",
    
    "dependencyConditions": [
    
    "Succeeded"
    
    ]
    
    }
    
    ],
    
    "userProperties": [],
    
    "typeProperties": {
    
    "variableName": "month",
    
    "value": {
    
    "value": "@split(pipeline().parameters.fileName,'-')[1]",
    
    "type": "Expression"
    
    }
    
    }
    
    },
    
    {
    
    "name": "date",
    
    "type": "SetVariable",
    
    "dependsOn": [
    
    {
    
    "activity": "month",
    
    "dependencyConditions": [
    
    "Succeeded"
    
    ]
    
    }
    
    ],
    
    "userProperties": [],
    
    "typeProperties": {
    
    "variableName": "date",
    
    "value": {
    
    "value": "@split(split(pipeline().parameters.fileName,'-')[2],'T')[0]",
    
    "type": "Expression"
    
    }
    
    }
    
    }
    
    ],
    
    "parameters": {
    
    "fileName": {
    
    "type": "string",
    
    "defaultValue": "2021-12-01T00:00:00Z.csv"
    
    }
    
    },
    
    "variables": {
    
    "year": {
    
    "type": "String"
    
    },
    
    "month": {
    
    "type": "String"
    
    },
    
    "date": {
    
    "type": "String"
    
    }
    
    },
    
    "annotations": [],
    
    "lastPublishTime": "2023-02-15T05:42:23Z"
    
    },
    
    "type": "Microsoft.DataFactory/factories/pipelines"
    
    }
    

    Output:

    Year:

    enter image description here

    Month

    enter image description here

    Date

    enter image description here

    Login or Signup to reply.
  2. Use a metadata activity to get the file list, and then a foreach activity to copy each file to the appropriate folder:

    pipline

    Metdata activity setting:

    metdata activity

    On foreach activity, in items loop through all the child items –

    @activity('Get files Metadata').output.childItems
    

    Inside the foreach look, add a copy activity to copy each file:

    Source:

    source copy

    Source dataset (with a parameter on filename, to copy one file only:

    source dataset

    Sync settings:

    sync settings

    Expression to pass to folder parameter:

    @concat(
       formatDateTime(item().name ,'yyyy'),
       '/',
       formatDateTime(item().name ,'MM'),
       '/',
       formatDateTime(item().name ,'dd')
    )
    

    Sync dataset, with a parameter on folder name to create the hierarchy:

    sync dataset

    The result:

    results

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search