Rename files (append timestamp) and move it to different folder on ADLS Gen2 (Databricks)

539 Views Asked by At

I want to append the timestamp into each file's name and move it to another folder on ADLS Gen2 from databricks notebook. I could list the file name as below.

fileList = dbutils.fs.ls(file_input)

for i in fileList:
  try:
    file_path = i.path
    #Rename the file appending timestamp
    parser = datetime.datetime.now()
    time_stamp = parser.strftime("%Y%m%d-%H%M%S")
    # Rename the files on ADLS Gen2 appennding time_stamp 

    #Move the file
    dbutils.fs.mv(file_path, file_path_archive)
  except Exception as e:
    raise Exception(str(e))

How to rename a file appending time stamp for a file on ADLSGen2. Thanks.

0

There are 0 best solutions below