简体   繁体   English

如何编写sails beanshell java 脚本来读取文件名以“SampleFile***.csv”开头的最新文件

[英]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.我正在尝试在需要读取文件并重命名它们的 beanshell 中编写 java。 But the problem is filename has appending number that changes everyday according to date, ex.但问题是文件名具有根据日期每天更改的附加数字,例如。 SampleFile0521, SampleFile0524.样本文件 0521,样本文件 0524。 And I need to read a File with latest timestamp and starts with SampleFile.我需要读取具有最新时间戳的文件并以 SampleFile 开头。

Can try writing the rename code in the Post-Iterate rule in the Sailpoint.可以尝试在 Sailpoint 中的 Post-Iterate 规则中编写重命名代码。

Your problem is not specific to Sailpoint IIQ or Beanshell.您的问题并非特定于 Sailpoint IIQ 或 Beanshell。 In fact, it seems to be a purely Java problem to be solved here.其实这里似乎是一个纯粹的Java问题要解决。

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?您是否尝试在分隔文件 IIQ 连接器中读取 CSV 文件? 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.这里似乎发生的是,您有一个分隔文件 IIQ 连接器,该连接器需要一个特定的输入文件(比如说 SampleFile.txt),但每天您只会得到一个像 SampleFileMMdd.txt 这样的新文件,您需要将其重命名为 SampleFile.txt处理前。

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...");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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