This can be acheived by the following java code -
Input: Directory Name
Output: Number of files suitable for processing
Names of files suitable for processing
Imports: import java.util.;
import java.io.;
IDataCursor idcPipeline = pipeline.getCursor();
//read the directory name from Pipeline
if (!idcPipeline.first(“directory”))
throw new ServiceException(“Directory is null!”);
String strDirectoryName = (String)idcPipeline.getValue();
//create handle to Directory and check existence and access
File directoryHandle = new File(strDirectoryName);
if(!(directoryHandle.canRead())) {
throw new ServiceException(strDirectoryName + " Directory does not have Read Permission!“);
}
if(!directoryHandle.exists() || !directoryHandle.isDirectory()) {
throw new ServiceException(strDirectoryName + " does not exist or is not a directory!”);
}
//get all elements in the directory
File arrDirectoryElementList;
arrDirectoryElementList = directoryHandle.listFiles();
int iDirectoryElementCount = arrDirectoryElementList.length;
//retrieve all the Files from the elements list
int iDirectoryFileCount = 0;
Vector filesVector = new Vector();
Vector fileModificationTimeVector = new Vector();
for (int i=0; i<iDirectoryElementCount; i++){
if(arrDirectoryElementList[i].isFile()) {
iDirectoryFileCount++;
filesVector.addElement(arrDirectoryElementList[i]);
//retrieve last modified time for the file - long value as milliseconds since the epoch
fileModificationTimeVector.addElement(new Long(arrDirectoryElementList[i].lastModified()));
}
}
if (iDirectoryFileCount < 1) {
//No files to list
IDataUtil.put(idcPipeline, “numFiles”, “0”);
IDataUtil.put(idcPipeline, “fileList”, new String[0]);
return;
}
//check file suitability for processing based on modified time
Vector suitableFilesVector = new Vector();
int iSuitableFileCount = 0;
Calendar calendar = Calendar.getInstance();
Long currentTime = calendar.getTimeInMillis();
for(int j=0; j<filesVector.size(); j++) {
Long fileModificationDate = (Long)fileModificationTimeVector.elementAt(j);
//elapsed time after creation (in ms)
Long timeDiff = currentTime - fileModificationDate;
//elapsed time after creation (in mins)
timeDiff = timeDiff/60000;
//if elapsed time is more than 15 mins, consider it suitable for processing
if(timeDiff >= 15) {
iSuitableFileCount++;
suitableFilesVector.addElement((File)filesVector.elementAt(j));
}
}
if (iSuitableFileCount < 1) {
//No suitable files
IDataUtil.put(idcPipeline, “numFiles”, “0”);
IDataUtil.put(idcPipeline, “fileList”, new String[0]);
return;
}
String arrSuitableFilesList = new String[iSuitableFileCount];
for(int k=0; k<iSuitableFileCount; k++) {
File file = (File)suitableFilesVector.elementAt(k);
arrSuitableFilesList[k] = file.getName();
}
IDataUtil.put(idcPipeline, “numFiles”, String.valueOf(iSuitableFileCount));
IDataUtil.put(idcPipeline, “fileList”, arrSuitableFilesList);
idcPipeline.destroy();
You may need to modify as per specific requirements like filetype, etc.
HTH