简体   繁体   中英

How do I write a sailpoint beanshell java script to read a latest file whose filename starts with ‘SampleFile***.csv’

I am trying to write a java in a beanshell where I need to read a file and rename them. But the problem is filename has appending number that changes everyday according to date, ex. SampleFile0521, SampleFile0524. And I need to read a File with latest timestamp and starts with SampleFile.

Can try writing the rename code in the Post-Iterate rule in the Sailpoint.

Your problem is not specific to Sailpoint IIQ or Beanshell. In fact, it seems to be a purely Java problem to be solved here.

However, your question lacks some information. What's the context here? Are you trying to read a CSV file in your delimited file IIQ connector? And after reading the file, you need to rename it? It's a lot of assumptions here.

What seems to be happening here is that you have a delimited file IIQ connector that expects a specific input file (let's say SampleFile.txt) but everyday you just get a new file like SampleFileMMdd.txt and you need to rename it to SampleFile.txt before processing.

If that's the case, you can try some code like this in your pre-processing rule.

    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
    String expectedFileName = "SampleFile"+sdf.format(new Date())+".txt";
    File dir = new File(<YOUR TARGET DIR HERE>);
    File f = new File(dir,expectedFileName);
    boolean worked = f.renameTo(new File(dir,"SampleFile.txt"));
    if (!worked) {
        //for example, there was already a file called SampleFile.txt up there
        throw new Exception("Could not rename the file...");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM