Hi @kazurayam,
I have now have a folder where I need to select the LAST record in the list, the 3rd one in this example:
11bfe1ce-d122-41dc-8016-f9bd5de24ee1.eml
11bfe1ce-d122-41dc-8016-f9bd5de24ee2.eml
11bfe1ce-d122-41dc-8016-f9bd5de24ee3.eml
How can I change .sorted(Comparator.reverseOrder()) to pick the LAST record in the list?
/**
* @author kazurayam
*/
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.stream.Collectors
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kazurayam.study20221030.PathComparableByFileLastModified
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.configuration.RunConfiguration
import internal.GlobalVariable as GlobalVariable
dataDir = Paths.get('//s-test-bsl1//MailerPickupDirectory')
List<PathComparableByFileLastModified> emlFiles =
Files.list(dataDir)
.filter({ p -> p.toString().endsWith(".eml") })
// wrap the Path object by a adapter class
// to sort the Path objects by the Email Date in the file content
.map({ p -> new PathComparableByFileLastModified(p) })
// in the descending order of the Date value
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList())
emlFiles.eachWithIndex { p, index ->
println((index + 1) + "\t" + p.getTimestampFormatted() + "\t" + dataDir.relativize(p.get()))
}
//Opens the 1st eml file and reads contents
String contentOfFirstFile = emlFiles.get(0).get().toFile().text
As always thank you for your feedback and taking your valuable time to look into my issue. I was able to solve my issue using a different method. If you are able, please delete my original post. Or I can delete the post if you are good with that.