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 .
Asked
Active
Viewed 612 times
1
-
1JavaScript and Java are vastly different languages. I changed the tag on your question to agree with what you wrote in the body text. Please check if correct. – Ole V.V. May 24 '21 at 06:32
-
It is. Sailpoint IIQ uses Beanshell scripts as "rules", and Beanshell uses quite the same Java syntax (not exactly the same thing but 90% is compatible) – shikida Jul 13 '21 at 19:49
2 Answers
1
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...");
}

shikida
- 485
- 2
- 10
-
This is a great example - interesting - is there a reason why you chose pre-processing instead of post-iterate? – Bob Aug 10 '21 at 15:53