moveDirectoryToDirectory(src, destDir, createDestDir); } else { moveFileToDirectory(src, destDir, createDestDir);
FileUtils.moveDirectoryToDirectory(file, tempZipDir, false); } else { FileUtils.moveFileToDirectory(file, tempZipDir, false);
@Test public void testIO300() throws Exception { final File testDirectory = getTestDirectory(); final File src = new File(testDirectory, "dir1"); final File dest = new File(src, "dir2"); assertTrue(dest.mkdirs()); assertTrue(src.exists()); try { FileUtils.moveDirectoryToDirectory(src, dest, false); fail("expected IOException"); } catch (final IOException ioe) { // expected } assertTrue(src.exists()); }
FileUtils.moveDirectoryToDirectory(src, destDir, true);
@Test public void testMoveDirectoryToDirectory_Errors() throws Exception { try { FileUtils.moveDirectoryToDirectory(null, new File("foo"), true); fail("Expected NullPointerException when source is null"); } catch (final NullPointerException e) { FileUtils.moveDirectoryToDirectory(new File("foo"), null, true); fail("Expected NullPointerException when destination is null"); } catch (final NullPointerException e) { FileUtils.moveDirectoryToDirectory(testFile1, testFile2, true); fail("Expected IOException when dest not a directory"); } catch (final IOException e) { FileUtils.moveDirectoryToDirectory(testFile1, nonexistant, false); fail("Expected IOException when dest does not exist and create=false"); } catch (final IOException e) {
@Test public void testMoveToDirectory_Errors() throws Exception { try { FileUtils.moveDirectoryToDirectory(null, new File("foo"), true); fail("Expected NullPointerException when source is null"); } catch (final NullPointerException e) { // expected } try { FileUtils.moveDirectoryToDirectory(new File("foo"), null, true); fail("Expected NullPointerException when destination is null"); } catch (final NullPointerException e) { // expected } final File nonexistant = new File(getTestDirectory(), "nonexistant"); final File destDir = new File(getTestDirectory(), "MoveToDirectoryDestDir"); try { FileUtils.moveToDirectory(nonexistant, destDir, true); fail("Expected IOException when source does not exist"); } catch (final IOException e) { // expected } }
public static boolean Version17MoveTheDiaryIntoNewDir(Context context) throws Exception { FileManager rootFileManager = new FileManager(context, FileManager.ROOT_DIR); File[] dataFiles = rootFileManager.getDir().listFiles(); boolean moveIntoNewDir = false; //router all dir first for (int i = 0; i < dataFiles.length; i++) { if (FileManager.isNumeric(dataFiles[i].getName()) && dataFiles[i].listFiles().length > 0) { moveIntoNewDir = true; break; } } //If the numeric dir is exist , move it if (moveIntoNewDir) { FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR); File destDir = diaryFM.getDir(); FileUtils.deleteDirectory(destDir); for (int i = 0; i < dataFiles.length; i++) { if (FileManager.isNumeric(dataFiles[i].getName())) { FileUtils.moveDirectoryToDirectory(dataFiles[i], new FileManager(context, FileManager.DIARY_ROOT_DIR).getDir() , true); } } //Remove the diary/temp/ FileUtils.deleteDirectory(new File(diaryFM.getDirAbsolutePath() + "/temp")); } return moveIntoNewDir; } }
public static boolean moveDirs(File source, File dest) { try { org.apache.commons.io.FileUtils.moveDirectoryToDirectory(source, dest, true); return true; } catch (Exception e) { LOGGER.error(e.getMessage()); } return false; }
/** * Copy the sourceDirectory to the given destinationDirectory */ public void moveDir(String sourceDirectoryPath, String destinationDirectoryPath) throws IOException{ File sourceDir = new File(sourceDirectoryPath); File destinationDir = new File(destinationDirectoryPath); FileUtils.moveDirectoryToDirectory(sourceDir, destinationDir, true); }
public static void moveFile(File resFile, String distFolder) throws IOException { if (resFile != null) { File distFile = new File(distFolder); if (resFile.isDirectory()) { FileUtils.moveDirectoryToDirectory(resFile, distFile, true); } else if (resFile.isFile()) { FileUtils.moveFileToDirectory(resFile, distFile, true); } } else { throw new IOException("resFile is null and distFolder: " + distFolder); } }
private static void moveToTopLevel(File from, File to) throws IOException { File[] list = from.listFiles(); if (list != null) { for (File file : list) { if (file.isDirectory()) { FileUtils.moveDirectoryToDirectory(file, to, false); } else { FileUtils.moveFileToDirectory(file, to, false); } } } }
public void renameExistingSharedConfigDirectory() { File configDirFile = new File(CONFIG_DIR_PATH); if (configDirFile.exists()) { String configDirFileName2 = CLUSTER_CONFIG_ARTIFACTS_DIR_NAME + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) + "." + System.nanoTime(); File configDirFile2 = new File(FilenameUtils.concat(configDirFileName2, configDirFileName2)); try { FileUtils.moveDirectoryToDirectory(configDirFile, configDirFile2, true); } catch (IOException e) { logger.info(e); } } } /***
public static synchronized void moveFileForce(File resFile,String distFolder) throws IOException{ File distFile = new File(distFolder); if (resFile.isDirectory()) { FileUtils.moveDirectoryToDirectory(resFile, distFile, true); } else if (resFile.isFile()) { File destFile = new File(distFolder, resFile.getName()); if (destFile.exists()){ destFile.delete(); } FileUtils.moveFileToDirectory(resFile, distFile, true); } } /**
private void moveOldIndexSnapshots() { try { FileUtils.moveDirectoryToDirectory(getSnapshotImportDirectory(), getSnapshotArchiveDirectory(), true); } catch (IOException ex) { LOG.error("Could not archive snapshot directory", ex); } }
private void replaceIndexes(final File workDir) throws IOException { // Ensure the indexing directory is empty File indexDirectory = new File(indexPathManager.getIndexRootPath()); // Delete the JIRA specific indexes. If plugins have added others, we don't want to blow them away FileUtils.deleteDirectory(new File(indexPathManager.getIssueIndexPath())); FileUtils.deleteDirectory(new File(indexPathManager.getCommentIndexPath())); FileUtils.deleteDirectory(new File(indexPathManager.getChangeHistoryIndexPath())); FileUtils.deleteDirectory(new File(indexPathManager.getWorklogIndexPath())); FileUtils.deleteDirectory(new File(indexPathManager.getSharedEntityIndexPath())); if (!indexDirectory.exists()) { indexDirectory.mkdir(); } FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.ISSUES_SUBDIR), indexDirectory, true); FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.COMMENTS_SUBDIR), indexDirectory, true); FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.CHANGE_HISTORY_SUBDIR), indexDirectory, true); FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.WORKLOGS_SUBDIR), indexDirectory, true); FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.ENTITIES_SUBDIR), indexDirectory, true); } }
moveDirectoryToDirectory(src, destDir, createDestDir); } else { moveFileToDirectory(src, destDir, createDestDir);
/** * Moves a file or directory to the destination directory. * <p> * When the destination is on another file system, do a "copy and delete". * * @param src the file or directory to be moved * @param destDir the destination directory * @param createDestDir If <code>true</code> create the destination directory, * otherwise if <code>false</code> throw an IOException * @throws NullPointerException if source or destination is <code>null</code> * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs moving the file * @since Commons IO 1.4 */ public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException { if (src == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!src.exists()) { throw new FileNotFoundException("Source '" + src + "' does not exist"); } if (src.isDirectory()) { moveDirectoryToDirectory(src, destDir, createDestDir); } else { moveFileToDirectory(src, destDir, createDestDir); } }
/** * Moves a file or directory to the destination directory. * <p> * When the destination is on another file system, do a "copy and delete". * * @param src the file or directory to be moved * @param destDir the destination directory * @param createDestDir If <code>true</code> create the destination directory, * otherwise if <code>false</code> throw an IOException * @throws NullPointerException if source or destination is <code>null</code> * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs moving the file * @since Commons IO 1.4 */ public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException { if (src == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!src.exists()) { throw new FileNotFoundException("Source '" + src + "' does not exist"); } if (src.isDirectory()) { moveDirectoryToDirectory(src, destDir, createDestDir); } else { moveFileToDirectory(src, destDir, createDestDir); } }
@Override public FileSystemEntryDTO moveDirectory(String fullPath, String newParent, String newName) throws FileErrorException { File basePath = new File(path); File directory = new File(basePath, fullPath); ensureLocalRoot(basePath, directory); ensureLocalRoot(basePath, directory); File baseDir = new File(basePath, newParent); ensureLocalRoot(basePath, baseDir); File newDir = new File(baseDir, newParent); try { FileUtils.moveDirectoryToDirectory(directory, newDir, true); FileSystemEntryDTO dto = new FileSystemEntryDTO(); dto.setFile(false); String absolutePath = newDir.getAbsolutePath(); String tmpPath = absolutePath.substring(path.length(), absolutePath.length()); dto.setFullPath(tmpPath); dto.setName(directory.getName()); return dto; } catch (IOException e) { logger.log(Level.SEVERE, "can not move directory", e); throw new FileErrorException(FileError.INVALID_STATE_ERR); } }
public static void moveDirectoryToDirectory(ActionContext actionContext) throws IOException{ Thing self = actionContext.getObject("self"); File srcDir = getFile(self, "getSrcDir", actionContext); File destDir = getFile(self, "getDestDir", actionContext); Boolean createDestDir = (Boolean) self.doAction("getCreateDestDir", actionContext); FileUtils.moveDirectoryToDirectory(srcDir, destDir, createDestDir); }