Share via


Azure data factory - Dynamically add timestamp in copied filename


Problem Statement:

​Azure data factory is copying files to the target folder and I need files to have current timestamp in it.

Example:
SourceFolder has files --> File1.txt, File2.txt and so on
TargetFolder should have copied files with the names --> File1_2019-11-01.txt, File2_2019-11-01.txt and so on.

Solution:

  1. Create a Source dataset that points to Source folder which has files to be copied. 

In Parameters tab - Define a parameter named - "Filename"


  

  1. Create a Target dataset that points to Target folder where files will be copied 

In Parameters tab - Define a parameter named - "TargetFilename"

  1. Drag a Get Metadata activity on pipeline. This will give us the file names having .txt extensions in the source folder. 

Add an argument - Child Items to retrieve files details under Source folder

  1. Connect above Get Metadata activity to ForEach activity

In Item field - add below expression to get all the source file names details that will be iterated in For each loop.

@activity('Get filenames').output.childItems
  1. In ForEach - Copy Activity, configure the Source and Sink fields like below. 

In Sink, use below expression that will append the current date to the file name. The format of datetime can be changed as per requirement.

@concat(replace(item().name,'.txt',''), '_', formatDateTime(utcnow(),'yyyy-MM-dd'), '.txt')