azure-data-factoryfile-renameformatdatetime

Rename files with format date as fileName_yyyy-MM-dd.csv and as fileName_dd-MM-yyyy.csv with ADF


I am uploading files from my company SFTP server to the Azure Storage Account called landing and the format date of my files are as follow:

5 files (fileName_dd-MM-yyyy.csv) 3 files (fileName_yyyy-MM-dd.csv)

My company wants me to rename them under this date format: fileName_yyyyMMdd.csv with ADF.

I tried with @concat('filename_', formatDateTime(utcnow(), 'yyyyMMdd'), '.csv') but I don't want utcnow, I want to change the format already present in the name of the file.

If anyone can help me with it.

Thank you.


Solution

  • You can use the below expression :

    to covert the file format : fileName_dd-MM-yyyy.csv into your expected. You can tweek the expression for other one.

    @concat(
      substring(pipeline().parameters.fileName, 0, add(indexOf(pipeline().parameters.fileName, '_'), 1)),
      substring(pipeline().parameters.fileName, add(indexOf(pipeline().parameters.fileName, '_'), 7), 4),
      substring(pipeline().parameters.fileName, add(indexOf(pipeline().parameters.fileName, '_'), 4), 2),
      substring(pipeline().parameters.fileName, add(indexOf(pipeline().parameters.fileName, '_'), 1), 2),
      '.csv'
    )