List of usage examples for org.apache.commons.io FileUtils moveFileToDirectory
public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) throws IOException
From source file:administraScan.OrganizaDirectorios.java
public void clasificarCAS() { String rutaCAS;/*from ww w . j a v a 2 s .c om*/ rutaCAS = conf.carpetaCAS + "\\"; File f = new File(rutaCAS); FileUtils Archivos = new FileUtils(); String curpct = ""; System.out.println("Archivo Leido en memoria:" + f.list()); ArrayList<String> names = new ArrayList<>(Arrays.asList(f.list())); System.out.println("" + names); if (!names.isEmpty()) { for (int i = 0; i < names.size(); i++) { System.out.println("Voy en :" + names.get(i)); String curp = (names.get(i).substring(0, 18)); System.out.println("Curp cortado" + curp); curpct = obtenerCT(curp); if (curp.equals("")) { System.out.println("Ya no hay Constancias que mover"); } else { System.out.println("" + curpct); String RutaOr = (conf.carpetaCAS + names.get(i).toString()); String RutaDest = (conf.carpetaCT + curpct + "\\" + curp + "\\"); System.out.println("" + RutaOr); System.out.println("" + RutaDest); File origen = new File(RutaOr); File destino = new File(RutaDest); try { Archivos.moveFileToDirectory(origen, destino, resultado); //Aqu se actualiza la variable } catch (IOException E) { E.printStackTrace(); } } } } }
From source file:com.wipro.ats.bdre.filemon.QueuedFileUploader.java
private static void hdfsCopy(FileCopyInfo fileCopying) throws IOException { try {/*from w w w . j av a 2s. com*/ // Copying file from local to HDFS overriding, if file already exists config.set("fs.defaultFS", FileMonRunnableMain.getDefaultFSName()); FileSystem fs = FileSystem.get(config); String destDir = fileCopying.getDstLocation(); Path destPath = new Path(ResolvePath.replaceVars(destDir)); if (!fs.exists(destPath)) { LOGGER.info("Creating HDFS dest dir " + destPath + " Success=" + fs.mkdirs(destPath)); } if (FileMonRunnableMain.isDeleteCopiedSrc()) { fs.copyFromLocalFile(true, true, new Path(fileCopying.getSrcLocation()), destPath); } else { fs.copyFromLocalFile(false, true, new Path(fileCopying.getSrcLocation()), destPath); File sourceFile = new File(fileCopying.getSrcLocation()); String arcDir = destDir.replace(FileMonRunnableMain.getHdfsUploadDir(), FileMonRunnableMain.getMonitoredDirName() + "/" + FileMonRunnableMain.ARCHIVE); File arcDirFile = new File(arcDir); FileUtils.moveFileToDirectory(sourceFile, arcDirFile, true); } } catch (Exception e) { FileMonitor.addToQueue(fileCopying.getFileName(), fileCopying); LOGGER.error("Error in executeCopyProcess method. Requeuing file " + fileCopying.getFileName(), e); throw new IOException(e); } }
From source file:de.uzk.hki.da.at.ATUseCaseRetrieval.java
@Test public void testHappyPath() throws Exception { String originalName = "ATUseCaseRetrieval"; ath.createObjectAndJob(originalName, "900"); ath.waitForJobToBeInStatus(originalName, "950"); System.out.println(new File(localNode.getUserAreaRootPath() + "/TEST/outgoing/ID-ATUseCaseRetrieval.tar") .getAbsolutePath());//from ww w . j a va 2 s . c o m assertTrue(new File(localNode.getUserAreaRootPath() + "/TEST/outgoing/ID-ATUseCaseRetrieval.tar").exists()); FileUtils.moveFileToDirectory( new File(localNode.getUserAreaRootPath() + "/TEST/outgoing/ID-ATUseCaseRetrieval.tar"), new File("/tmp"), false); ArchiveBuilderFactory.getArchiveBuilderForFile(new File("/tmp/ID-ATUseCaseRetrieval.tar")) .unarchiveFolder(new File("/tmp/ID-ATUseCaseRetrieval.tar"), new File("/tmp/")); if (!new File("/tmp/ID-ATUseCaseRetrieval/data/" + "image/713091.tif").exists()) fail(); if (!new File("/tmp/ID-ATUseCaseRetrieval/data/" + "premis.xml").exists()) fail(); if (!bagIsValid(new File("/tmp/ID-ATUseCaseRetrieval"))) fail(); }
From source file:com.zyz.mobile.file.FileClipboard.java
/** * Move the specified file/directory to the destination directory. * * @param srcFile the file/directory to be moved * @param destDir the destination directory * @throws IOException/*from ww w .j a v a 2 s.c o m*/ */ public static void moveFileToDirectory(File srcFile, File destDir) throws IOException { if (srcFile.isDirectory()) { FileUtils.moveDirectoryToDirectory(srcFile, destDir, true); } else { FileUtils.moveFileToDirectory(srcFile, destDir, false); } }
From source file:de.uzk.hki.da.at.ATRetrieval.java
@Test public void testHappyPath() throws Exception { ath.createJob(originalName, "900"); ath.waitForJobToBeInStatus(originalName, "952"); assertTrue("Temp Daten aus der Datenbank noch nicht bereinigt", !nonPersistPropertiesExist(ath.getObject(originalName))); System.out.println(new File(localNode.getUserAreaRootPath() + "/" + testContractor.getUsername() + "/outgoing/" + identifier + ".tar").getAbsolutePath()); assertTrue(new File(localNode.getUserAreaRootPath() + "/" + testContractor.getUsername() + "/outgoing/" + identifier + ".tar").exists()); FileUtils.moveFileToDirectory(new File(localNode.getUserAreaRootPath() + "/" + testContractor.getUsername() + "/outgoing/" + identifier + ".tar"), new File("/tmp"), false); //after moving the retrieval-file, PostRetrievalAction(952) have to end the workflow Thread.sleep((int) (PostRetrievalAction.PAUSE_DELAY * 1.2)); ath.awaitObjectState(originalName, Object.ObjectStatus.ArchivedAndValidAndNotInWorkflow); ArchiveBuilderFactory.getArchiveBuilderForFile(new File("/tmp/" + identifier + ".tar")) .unarchiveFolder(new File("/tmp/" + identifier + ".tar"), new File("/tmp/")); if (!new File("/tmp/" + identifier + "/data/" + "image/713091.tif").exists()) fail();// w w w . j av a 2s . com if (!new File("/tmp/" + identifier + "/data/" + "premis.xml").exists()) fail(); if (!bagIsValid(new File("/tmp/" + identifier))) fail(); }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncCopyMoveTask.java
@Override protected Boolean doInBackground(String... params) { try {/*from w w w . j a v a 2 s . c o m*/ if (mSourceFile.getCanonicalPath() == mDestinationFile.getCanonicalPath()) { Toast.makeText(mContext, R.string.source_target_same, Toast.LENGTH_LONG).show(); return false; } } catch (Exception e) { return false; } if (mSourceFile.isDirectory()) { try { if (mShouldMove) FileUtils.moveDirectoryToDirectory(mSourceFile, mDestinationFile, true); else FileUtils.copyDirectoryToDirectory(mSourceFile, mDestinationFile); } catch (Exception e) { return false; } } else { try { if (mShouldMove) FileUtils.moveFileToDirectory(mSourceFile, mDestinationFile, true); else FileUtils.copyFile(mSourceFile, mDestinationFile); } catch (Exception e) { return false; } } return true; }
From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java
protected void moveFile(Resource sOriginFile, Resource sDestinationFile) throws IOException { File aOrigineFile = sOriginFile.getFile(); if (aOrigineFile.isFile()) { if (!isDirectory(sDestinationFile)) { FileUtils.moveFile(aOrigineFile, sDestinationFile.getFile()); } else {//w ww . j a va 2s .c o m FileUtils.moveFileToDirectory(aOrigineFile, sDestinationFile.getFile(), true); } } else { FileUtils.moveDirectoryToDirectory(aOrigineFile, sDestinationFile.getFile(), true); } }
From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java
/** * Move template file and rename it./*from w w w . j a v a 2 s . c o m*/ * * @param root * @param templateFolder * @param templateFilename * @throws SiteWhereException */ protected static void migrateTemplateFile(File root, File templateFolder, String templateFilename) throws SiteWhereException { try { File templateFile = new File(root, templateFilename); FileUtils.moveFileToDirectory(templateFile, templateFolder, false); File moved = new File(templateFolder, templateFilename); File updated = new File(templateFolder, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_CONFIGURATION_FILE + "." + FileSystemTenantConfigurationResolver.TENANT_SUFFIX_ACTIVE); if (!moved.getAbsolutePath().equals(updated.getAbsolutePath())) { FileUtils.moveFile(moved, updated); } } catch (IOException e) { throw new SiteWhereException("Unable to migrate template file.", e); } }
From source file:com.github.cbismuth.fdupes.io.PathOrganizer.java
private void onNoTimestampPath(final Path destination, final PathElement pathElement, final AtomicInteger counter) { final Path path = pathElement.getPath(); final String baseName = FilenameUtils.getBaseName(path.toString()); final int count = counter.getAndIncrement(); final String extension = FilenameUtils.getExtension(path.toString()); final String newName = String.format("%s-%d.%s", baseName, count, extension); final Path sibling = path.resolveSibling(newName); try {// w w w. j a v a 2s .c om FileUtils.moveFile(path.toFile(), sibling.toFile()); FileUtils.moveFileToDirectory(sibling.toFile(), Paths.get(destination.toString(), "misc").toFile(), true); } catch (final IOException e) { LOGGER.error(e.getMessage()); } }
From source file:it.geosolutions.geobatch.actions.commons.MoveAction.java
/** * Removes TemplateModelEvents from the queue and put *//*w w w .j a v a 2s . c o m*/ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.started(); listenerForwarder.setTask("build the output absolute file name"); // return final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.setTask("Building/getting the root data structure"); boolean moveMultipleFile; final int size = events.size(); if (size == 0) { throw new ActionException(this, "Empty file list"); } else if (size > 1) { moveMultipleFile = true; } else { moveMultipleFile = false; } if (conf.getDestination() == null) { throw new IllegalArgumentException("Unable to work with a null dest dir"); } if (!conf.getDestination().isAbsolute()) { conf.setDestination(new File(this.getConfigDir(), conf.getDestination().getPath())); if (LOGGER.isWarnEnabled()) { LOGGER.warn("Destination is not an absolute path. Absolutizing destination using temp dir: " + conf.getDestination()); } } boolean moveToDir; if (!conf.getDestination().isDirectory()) { // TODO LOG moveToDir = false; if (moveMultipleFile) { throw new ActionException(this, "Unable to run on multiple file with an output file, use directory instead"); } } else { moveToDir = true; } while (!events.isEmpty()) { listenerForwarder.setTask("Generating the output"); final EventObject event = events.remove(); if (event == null) { // TODO LOG continue; } if (event instanceof FileSystemEvent) { File source = ((FileSystemEvent) event).getSource(); File dest; listenerForwarder.setTask("moving to destination"); if (moveToDir) { dest = conf.getDestination(); try { FileUtils.moveFileToDirectory(source, dest, true); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage()); } } else if (moveMultipleFile) { dest = new File(conf.getDestination(), source.getPath()); try { FileUtils.moveFile(source, dest); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage()); } } else { // LOG continue continue; } // add the file to the return ret.add(new FileSystemEvent(dest, FileSystemEventType.FILE_ADDED)); } } listenerForwarder.completed(); return ret; }