Search code examples
etlinformaticainformatica-powercenter

Pick the latest file based on datestamp provided in the filename


I have to pick the latest files and copy it to the target folder. For example below are my files in C:\Users\ and the date stamp is after the third underscore i.e. 20240210 in the first file below. so out of 4 files below, AAA_PPP_51_20240302 is the first file. How do I do this in Informatica PowerCenter?

1.AAA_PPP_51_20240210
2.AAA_PPP_51_20240217
3.AAA_PPP_51_20240224
4.AAA_PPP_51_20240302

Solution

  • use a command task or pre-session command task to create a list file with latest file. Then load only that file.

    1. use command ls -Art | tail -n 1 > file_list.txt
    2. use file_list.txt in session as a file input. And use indirect file read in session.

    If you are using Windows, then you have to create a bat file and call it in command task in Infa. You can use below script and save it as my_command.bat

    for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
    echo  %LAST% >file_list.txt