Source:
public void run(ActionContext context) throws Exception { Path source = new Path(config.sourcePath); Path dest = new Path(config.destPath); FileSystem fileSystem = source.getFileSystem(new Configuration()); if (fileSystem.getFileStatus(source).isFile()) { try { if (!fileSystem.rename(source, dest)) { if (!config.continueOnError) { throw new IOException(String.format("Failed to rename file to {}", source.toString(), dest.toString())); } LOG.error("Failed to move file to {}", source.toString(), dest.toString()); } } catch (IOException e) { if (!config.continueOnError) { throw e; } LOG.error("Failed to move file to {}", source.toString(), dest.toString(), e); } return; } FileStatus[] listFiles; if (config.fileRegex != null) { PathFilter filter = new PathFilter() { private final Pattern pattern = Pattern.compile(config.fileRegex); @Override public boolean accept(Path path) { return pattern.matcher(path.getName()).matches(); } }; listFiles = fileSystem.listStatus(source, filter); } else { listFiles = fileSystem.listStatus(source); } for (FileStatus file: listFiles) { source = file.getPath(); dest = new Path(config.destPath); try { if (!fileSystem.rename(source, dest)) { if (!config.continueOnError) { throw new IOException(String.format("Failed to rename file to {}", source.toString(), dest.toString())); } LOG.error("Failed to move file to {}", source.toString(), dest.toString()); } } catch (IOException e) { if (!config.continueOnError) { throw e; } LOG.error("Failed to move file to {}", source.toString(), dest.toString(), e); } } }

Target:
public void run(ActionContext context) throws Exception { Path source = new Path(config.sourcePath); Path dest = new Path(config.destPath); FileSystem fileSystem = source.getFileSystem(new Configuration()); fileSystem.mkdirs(dest.getParent()); if (fileSystem.getFileStatus(source).isFile()) { try { if (!fileSystem.rename(source, dest)) { if (!config.continueOnError) { throw new IOException(String.format("Failed to rename file to {}", source.toString(), dest.toString())); } LOG.error("Failed to move file to {}", source.toString(), dest.toString()); } } catch (IOException e) { if (!config.continueOnError) { throw e; } LOG.error("Failed to move file to {}", source.toString(), dest.toString(), e); } return; } FileStatus[] listFiles; if (config.fileRegex != null) { PathFilter filter = new PathFilter() { private final Pattern pattern = Pattern.compile(config.fileRegex); @Override public boolean accept(Path path) { return pattern.matcher(path.getName()).matches(); } }; listFiles = fileSystem.listStatus(source, filter); } else { listFiles = fileSystem.listStatus(source); } if (listFiles.length == 0) { if (config.fileRegex != null) { LOG.warn("Not moving any files of type from source {}", config.fileRegex, source.toString()); } else { LOG.warn("Not moving any files from source {}", source.toString()); } } if (fileSystem.isFile(dest)) { throw new IllegalArgumentException(String.format("destPath %s needs to be a directory since sourcePath is a " + "directory", config.destPath)); } fileSystem.mkdirs(dest); for (FileStatus file: listFiles) { source = file.getPath(); try { if (!fileSystem.rename(source, dest)) { if (!config.continueOnError) { throw new IOException(String.format("Failed to rename file to {}", source.toString(), dest.toString())); } LOG.error("Failed to move file to {}", source.toString(), dest.toString()); } } catch (IOException e) { if (!config.continueOnError) { throw e; } LOG.error("Failed to move file to {}", source.toString(), dest.toString(), e); } } }