How to configure the SystemExecute component to delete a list of files? I want to use an input port with a list of files that the SystemExecute component will then delete. Pretty straight forward but I cannot figure out how to reference the input port field within the system command.
Input port in SystemExecute component is just redirected stdin. So on Linux the issue can be resolved by setting “xargs rm” as command attribute. Then values from input records
are treated as arguments for rm command.
The issue can be also hacked by Reformat component. Just for each input record create file with name provided by input data record, delete it and return SKIP from transform method:
import java.io.File;
import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataRecord;
import org.jetel.exception.TransformException;
public class Rm extends DataRecordTransform {
File toRemove;
public int transform(DataRecord[] arg0, DataRecord[] arg1)
throws TransformException {
toRemove = new File(arg0[0].getField(0).toString());
if (!toRemove.delete()) {
errorMessage = "Can't remove " + toRemove.getPath();
return -2;
}
return SKIP;
}
}