0

In my case, when my SOAP request is polled, there will be few files generated in c:/storage/fghjk/ folder.

When I send the request again, another random folder will be created and the files be created there. (c:/storage/ngjdhd/)

Any idea How I can handle my code to handle this randomly generated folder?

I tried using regex but failed. Finally ended up with some inefficient code. which I am not happy about.

String randomFolder = null;
for (String fileToCheck : files) {
    File folder = new File(location);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles[0].isDirectory()) {
        randomFolder = listOfFiles[0].getName();
    }
    String filePath = location + "/" + randomFolder + "/" + fileToCheck.trim();
    File currentFile = new File(FilenameUtils.normalize(filePath, Boolean.TRUE));
    assertTrue(currentFile.exists(), "Existence of file \"" + currentFile + "\"");
}
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • Why do you say the code is inefficient? What other logic did you consider? – Dakshinamurthy Karra Jan 10 '19 at 10:42
  • Possible duplicate of [How to read all files in a folder from Java?](https://stackoverflow.com/questions/1844688/how-to-read-all-files-in-a-folder-from-java) – TiyebM Jan 10 '19 at 11:19
  • 1
    why don't you get the existed folders list before request get updates and then again get the folders list and compare them, do action based on resulted folders – Ryuzaki L Jan 10 '19 at 17:50

0 Answers0