Search code examples
azureazure-logic-apps

Azure Logic App, Delete old file only when a new one comes in


I am working on a logic app solution where I have to delete the older file only when the new one comes in. For e.g a file named "text 04/10/2023" should be deleted once "text 04/15/2023" comes in and till the new file comes in I want to re-load the same file "text 04/10/2023" into the database. I have everything set to load the file but unable to understand or figure out how to delete the files.

The logic reads a file from the blob loads it into the database, and it can remove the current file. But once the current file is removed it can no longer be re-processed till the new one comes in.


Solution

  • You can use copy/delete blob actions to move the currently processed file between logical folders, to save it for subsequent runs, if needed. Use Two Logical folders : <inbound_folder>, <done_folder>

    At the end of processing, you could copy the <inbound_folder>\04102023.txt file to a different destination <done_folder>\04102023.txt within the container and then delete the <inbound_folder>\04102023.txt file.

    At the start of processing, if <inbound_folder> is empty, then you could check the *<done_folder> for presence of any .txt file, and process it. Leave it in the *<done_folder> itself after processing. If <inbound_folder> is not empty, then process the new file, empty the <done_folder> and then finally move(copy/delete blob) the new file to <done_folder>