Customer Portal

How to delete a list of files

Comments 1

  • Avatar
    avackova
    0
    Comment actions Permalink
    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;
    }

    }

Please sign in to leave a comment.