簡體   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’

我正在嘗試在需要讀取文件並重命名它們的 beanshell 中編寫 java。 但問題是文件名具有根據日期每天更改的附加數字,例如。 樣本文件 0521,樣本文件 0524。 我需要讀取具有最新時間戳的文件並以 SampleFile 開頭。

可以嘗試在 Sailpoint 中的 Post-Iterate 規則中編寫重命名代碼。

您的問題並非特定於 Sailpoint IIQ 或 Beanshell。 其實這里似乎是一個純粹的Java問題要解決。

但是,您的問題缺少一些信息。 這里的上下文是什么? 您是否嘗試在分隔文件 IIQ 連接器中讀取 CSV 文件? 並且在讀取文件后,您需要重命名它嗎? 這里有很多假設。

這里似乎發生的是,您有一個分隔文件 IIQ 連接器,該連接器需要一個特定的輸入文件(比如說 SampleFile.txt),但每天您只會得到一個像 SampleFileMMdd.txt 這樣的新文件,您需要將其重命名為 SampleFile.txt處理前。

如果是這種情況,您可以在預處理規則中嘗試類似這樣的代碼。

    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