You could read the file names from the directory and store them in an entity, then loop over the retrieved list of file names. For getting the filenames from the directory use a java action like below. This takes the import directory as string argument and will create all filenames in an entity called fileNames and returns the list of fileNames objects in the microflow. The commit action might not even be needed and then you just have a list of names in memory. Be aware when the list gets large you might run into memory issues
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import myfirstmodule.proxies.fileNames;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
public class Java_action extends CustomJavaAction<java.util.List<IMendixObject>>
{
private String dirName;
public Java_action(IContext context, String dirName)
{
super(context);
this.dirName = dirName;
}
@Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
// BEGIN USER CODE
try {
File folder = new File(dirName);
File[] listOfFiles = folder.listFiles();
List<IMendixObject> fileList = new ArrayList<>();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
Core.getLogger("Files").debug("File " + listOfFiles[i].getName());
fileNames filename = new fileNames(getContext());
filename.setFileName(listOfFiles[i].getName());
filename.commit();
fileList.add(filename.getMendixObject());
} else if (listOfFiles[i].isDirectory()) {
Core.getLogger("Files").debug("Directory " + listOfFiles[i].getName());
}
}
return fileList;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
// END USER CODE
}