Hi,
You can use the following code for java service. Import java.IO.File, java.util.*, java.lang.String packages in the ‘shared’ section of the java service. The input is ‘filepath’ string output if fileList doc list and length (no of files)
IDataCursor pipelineCursor = pipeline.getCursor();
String filepath = IDataUtil.getString( pipelineCursor, "filepath" );
try {
String fileSep = System.getProperty("file.separator");
File f1 = new File (filepath);
if (f1.exists ()) {
String filenames1 [] = f1.list();
IData[] fileList = new IData[filenames1.length];
String type = "";
int j = 0;
for (int i = 0; i < filenames1.length; i ++) {
File f2 = new File ( filepath + fileSep + filenames1[i]);
if (f2.isDirectory ())
type = "d";
else {
if (filenames1[i].endsWith("zip"))
type="z";
else
type = "f";
}
fileList[j] = IDataFactory.create();
IDataCursor fileListCursor = fileList[j].getCursor();
IDataUtil.put( fileListCursor, "fileName", filenames1[i] );
IDataUtil.put( fileListCursor, "size", String.valueOf(f2.length()));
IDataUtil.put( fileListCursor, "type", type );
fileListCursor.destroy();
j ++;
}
IDataUtil.put( pipelineCursor, "fileList", fileList );
IDataUtil.put( pipelineCursor, "length", String.valueOf(j));
} else {
IDataUtil.put( pipelineCursor, "message", filepath + " directory does not exist");
}
} finally {
if (pipelineCursor != null)
pipelineCursor.destroy();
}
Cheers
Guna
#Flow-and-Java-services#webMethods#Integration-Server-and-ESB