KAPOW

Would you like to react to this message? Create an account in a few clicks or log in to continue.
KAPOW

Welcome to the Kapow forum. Here you can get help, use your skills to help others and enjoy hanging out in the company of other Kapow Robot Developers.


2 posters

    Extract the latest file based on filename

    avatar
    parvathy.sunil


    Posts : 3
    Points : 1557
    Join date : 2019-12-30

    Extract the latest file based on filename Empty Extract the latest file based on filename

    Post by parvathy.sunil Thu Feb 06, 2020 11:29 am

    Hello all,
    I have a folder that contains few excel files which are named with dates date,month,year and time(hhmm)
    for example file name- Test_01022020_0530 (here-01 stands for day,02 stands for month,2020 stands for year,05 is hours and 30 is minutes). 

    Lets say I have 4 excel files of the following  name pattern
    Test_02012020_0120
    Test_03012020_0230
    Test_01022020_0530
    Test_07012020_0400


    In the above four files, how do I extract the file which has the latest date attached to the file name.


    It would be really great if anyone could help me out with the issue.

    Regards.
    Parvathy sunil.
    avatar
    Andy22289


    Posts : 4
    Points : 1977
    Join date : 2018-11-09

    Extract the latest file based on filename Empty Re: Extract the latest file based on filename

    Post by Andy22289 Thu Feb 06, 2020 5:40 pm

    I first created a variable called 'LatestFileDate' and gave it a starting value of "1900-01-01 00:00:00.0". I've also made this a global variable.

    Then using a 'For Each File' loop, loop through all files in your folder storing the 'FileName' in a variable. Following this, use an Assign Variable step to extract the date from 'FileName' and store this as 'FileDate' in another variable.

    Finally, using another Assign Variable step, you could use expression 'FileDate>LatestFileDate ? FileDate : LatestFileDate' to update the 'LatestFileDate' variable with the latest date.  If you are not familiar with 'If - Then - Else' statements in Kofax RPA, this statement is saying If FileDate is greater than LatestFileDate, Then use FileDate, Else use LatestFileDate.  As we have set this to then store the result back in the 'LatestFileDate' variable, once we have looped through all files in our folder we will end up with the latest date in our 'LatestFileDate' variable.

    If you then want to go on and open this file, you would start a new branch and use a Convert Variable step to convert your 'LatestFileDate' back into the format used in your file name, and then use this value in a Load File step to open the file.

    I've attached some screenshots showing this.

    Extract the latest file based on filename 110

    Extract the latest file based on filename 210

    Extract the latest file based on filename 310

    Extract the latest file based on filename 410

    Extract the latest file based on filename 510
    avatar
    parvathy.sunil


    Posts : 3
    Points : 1557
    Join date : 2019-12-30

    Extract the latest file based on filename Empty Re: Extract the latest file based on filename

    Post by parvathy.sunil Fri Feb 07, 2020 11:13 am

    Thank you so much.....It was really helpful

    Sponsored content


    Extract the latest file based on filename Empty Re: Extract the latest file based on filename

    Post by Sponsored content


      Current date/time is Fri Mar 29, 2024 5:52 am