Data360 Analyze

 View Only
  • 1.  Rename File in Directory Dynamically Based On Another File

    Employee
    Posted 07-15-2020 12:16

    I have a data flow I'm working on but need help on one piece of it. At a certain point I will have a directory with five (5) files in it. Next the data flow will delete one of those files...we'll call it "File_20200715_05.txt" and replace it with a generic file called "File_05.txt". 

    Now I need to rename the generic file, "File_05.txt", with the name of the previous file...which is dynamic. In the directory I have four other files with a similar naming convention which in theory I could use to rename the new file:

    • File_20200715_01.txt
    • File_20200715_02.txt
    • File_20200715_03.txt
    • File_20200715_04.txt

    I'm wondering if there is a way to utilize one of those to capture everything before the final _##.txt and rename my current "File_05.txt" to "File_20200715_05.txt". Any thoughts or suggestions are appreciated?

    Thank you!



  • 2.  RE: Rename File in Directory Dynamically Based On Another File

    Employee
    Posted 07-16-2020 03:13

    Hi Joshua,

    I'm not entirely sure I understand the scenario but the attached data flow may provide some pointers.

    The Run Dependencies provide a mechanism to sequence the execution of sub-flows within the data flow. 

    You can use some Python code within a Transform node to delete a specified file:

    Once the file has been deleted you can process and write the data to the intermediate file name. 

    Another Transform node can be used to rename a file:

    See the attached .lna file.

     

     

    Attached files

    Rename_File_Tests - 16 Jul 2020.lna

     



  • 3.  RE: Rename File in Directory Dynamically Based On Another File

    Employee
    Posted 07-16-2020 09:17

    Adrian,

    I think this is on the right track. I made a slight adjustment to your "Delete File If Exists" Transform Node and I was able to get what I wanted. Thanks so much for your assistance!

    Josh

     

    Attached files

    Screen Shot 2020-07-16 at 11.15.14 AM.png
    Screen Shot 2020-07-16 at 11.15.39 AM.png