List of usage examples for org.apache.commons.io FileUtils moveDirectoryToDirectory
public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) throws IOException
From source file:kr.co.leem.system.FileSystemUtils.java
/** * ??./* w ww . j a va 2s . com*/ * * @param srcDir ? . * @param destDir ?? . * @param createDestDir ? . * @see FileUtils#moveDirectoryToDirectory(File, File, boolean) */ public static void moveDirectoryToDirectory(final String src, final String destDir, final boolean createDestDir) { processIO(new IOCallback<Object>() { public Object doInProcessIO() throws IOException, NullPointerException { FileUtils.moveDirectoryToDirectory(new File(src), new File(destDir), createDestDir); return null; } }); }
From source file:de.jwi.jfm.Folder.java
private String pasteClipboard(HttpSession session) throws OutOfSyncException, IOException { ClipBoardContent clipBoardContent = (ClipBoardContent) session.getAttribute("clipBoardContent"); if (clipBoardContent == null) { return "nothing in clipboard"; }//from ww w. jav a 2s .c o m for (int i = 0; i < clipBoardContent.selectedfiles.length; i++) { File f = clipBoardContent.selectedfiles[i]; File f1 = f.getParentFile(); if (myFile.getCanonicalFile().equals(f1.getCanonicalFile())) { return "same folder"; } } for (int i = 0; i < clipBoardContent.selectedfiles.length; i++) { File f = clipBoardContent.selectedfiles[i]; if (clipBoardContent.contentType == ClipBoardContent.COPY_CONTENT) { if (f.isDirectory()) { FileUtils.copyDirectoryToDirectory(f, myFile); } else { FileUtils.copyFileToDirectory(f, myFile, true); } } if (clipBoardContent.contentType == ClipBoardContent.CUT_CONTENT) { if (f.isDirectory()) { FileUtils.moveDirectoryToDirectory(f, myFile, false); } else { FileUtils.moveFileToDirectory(f, myFile, false); } } if (clipBoardContent.contentType == ClipBoardContent.CUT_CONTENT) { session.removeAttribute("clipBoardContent"); } } return ""; }
From source file:com.googlecode.gwtphonegap.server.file.FileRemoteServiceServlet.java
@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);//from w w w .j a va 2s. c o m 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); } }
From source file:com.daphne.es.maintain.editor.web.controller.OnlineEditorController.java
@RequestMapping("move") public String move(@RequestParam(value = "descPath") String descPath, @RequestParam(value = "paths") String[] paths, @RequestParam(value = "conflict") String conflict, RedirectAttributes redirectAttributes) throws IOException { String rootPath = sc.getRealPath(ROOT_DIR); descPath = URLDecoder.decode(descPath, Constants.ENCODING); for (int i = 0, l = paths.length; i < l; i++) { String path = paths[i];/*from w w w . ja va 2 s .c o m*/ path = URLDecoder.decode(path, Constants.ENCODING); paths[i] = (rootPath + File.separator + path).replace("\\", "/"); } try { File descPathFile = new File(rootPath + File.separator + descPath); for (String path : paths) { File sourceFile = new File(path); File descFile = new File(descPathFile, sourceFile.getName()); if (descFile.exists() && "ignore".equals(conflict)) { continue; } FileUtils.deleteQuietly(descFile); if (sourceFile.isDirectory()) { FileUtils.moveDirectoryToDirectory(sourceFile, descPathFile, true); } else { FileUtils.moveFileToDirectory(sourceFile, descPathFile, true); } } redirectAttributes.addFlashAttribute(Constants.MESSAGE, "??"); } catch (Exception e) { redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage()); } redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING)); return redirectToUrl(viewName("list")); }
From source file:org.alex73.skarynka.scan.process.ProcessCommands.java
public static String call(String s) throws Exception { LOG.info("Parse command: " + s); StringBuilder out = new StringBuilder(); Matcher m;/* w w w . j av a 2 s . co m*/ if ((m = DO_LS.matcher(s)).matches()) { LOG.info("Command ls " + m.group(1)); List<File> files = new ArrayList<>(FileUtils.listFiles(new File(m.group(1)), null, true)); Collections.sort(files); out.append(s + ":\n"); for (File f : files) { out.append(" " + f.getPath() + " " + f.length() + "\n"); } } else if ((m = DO_DF.matcher(s)).matches()) { LOG.info("Command df " + m.group(1)); File f = new File(m.group(1)); long gb = f.getFreeSpace() / 1024 / 1024 / 1024; out.append(s + ": " + gb + " gb\n"); } else if ((m = DO_RM.matcher(s)).matches()) { LOG.info("Command rm " + m.group(1)); File f = new File(m.group(1)); if (f.isDirectory()) { FileUtils.deleteDirectory(f); } else { f.delete(); } } else if ((m = DO_CP.matcher(s)).matches()) { LOG.info("Command cp " + m.group(1) + " " + m.group(2)); FileUtils.copyFile(new File(m.group(1)), new File(m.group(2))); } else if ((m = DO_MVDIR.matcher(s)).matches()) { LOG.info("Command mvdir " + m.group(1) + " " + m.group(2)); FileUtils.moveDirectoryToDirectory(new File(m.group(1)), new File(m.group(2)), true); } else { throw new Exception("Unknown command: " + s); } return out.toString(); }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
public void renameExistingSharedConfigDirectory() { File configDirFile = new File(configDirPath); 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 {/*from w ww . ja va2s . c o m*/ FileUtils.moveDirectoryToDirectory(configDirFile, configDirFile2, true); } catch (IOException e) { logger.info(e); } } }
From source file:org.craftercms.studio.impl.v1.repository.disk.DiskContentRepository.java
@Override public boolean moveContent(String fromPath, String toPath, String newName) { boolean success = true; try {// ww w.j a va2s.c o m File source = constructRepoPath(fromPath).toFile(); File destDir = constructRepoPath(toPath).toFile(); if (!destDir.exists()) { destDir.mkdirs(); } File dest = destDir; if (StringUtils.isNotEmpty(newName)) { dest = new File(destDir, newName); } if (source.isDirectory()) { File[] dirList = source.listFiles(); for (File file : dirList) { if (file.isDirectory()) { FileUtils.moveDirectoryToDirectory(file, dest, true); } else { FileUtils.moveFileToDirectory(file, dest, true); } } source.delete(); } else { if (dest.isDirectory()) { FileUtils.moveFileToDirectory(source, dest, true); } else { source.renameTo(dest); } } } catch (Exception err) { // log this error success = false; } return success; }
From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepository.java
@Override public boolean moveContent(String site, String fromPath, String toPath, String newName) { boolean success = true; try {/*from www .j a va 2 s. c o m*/ Repository repo; if (StringUtils.isEmpty(site)) { repo = getGlobalConfigurationRepositoryInstance(); } else { repo = getSiteRepositoryInstance(site); } String gitFromPath = getGitPath(fromPath); RevTree fromTree = getTree(repo); TreeWalk fromTw = TreeWalk.forPath(repo, gitFromPath, fromTree); String gitToPath = getGitPath(toPath); RevTree toTree = getTree(repo); TreeWalk toTw = TreeWalk.forPath(repo, gitToPath, toTree); FS fs = FS.detect(); File repoRoot = repo.getWorkTree(); Path sourcePath = null; if (fromTw == null) { sourcePath = Paths.get(fs.normalize(repoRoot.getPath()), gitFromPath); } else { sourcePath = Paths.get(fs.normalize(repoRoot.getPath()), fromTw.getPathString()); } Path targetPath = null; if (toTw == null) { targetPath = Paths.get(fs.normalize(repoRoot.getPath()), gitToPath); } else { targetPath = Paths.get(fs.normalize(repoRoot.getPath()), toTw.getPathString()); } File source = sourcePath.toFile(); File destDir = targetPath.toFile(); File dest = destDir; if (StringUtils.isNotEmpty(newName)) { dest = new File(destDir, newName); } if (source.isDirectory()) { File[] dirList = source.listFiles(); for (File file : dirList) { if (file.isDirectory()) { FileUtils.moveDirectoryToDirectory(file, dest, true); } else { FileUtils.moveFileToDirectory(file, dest, true); } } source.delete(); } else { if (dest.isDirectory()) { FileUtils.moveFileToDirectory(source, dest, true); } else { source.renameTo(dest); } } Git git = new Git(repo); git.add().addFilepattern(gitToPath).call(); git.rm().addFilepattern(gitFromPath).call(); RevCommit commit = git.commit().setOnly(gitFromPath).setOnly(gitToPath).setMessage(StringUtils.EMPTY) .call(); } catch (IOException | GitAPIException err) { // log this error logger.error("Error while moving content from {0} to {1}", err, fromPath, toPath); success = false; } return success; }
From source file:org.exist.replication.jms.obsolete.FileSystemListener.java
private void handleCollection(eXistMessage em) { File src = new File(baseDir, em.getResourcePath()); switch (em.getResourceOperation()) { case CREATE://from w w w.j a v a2 s. c o m case UPDATE: try { // Create dirs if not existent FileUtils.forceMkdir(src); } catch (IOException ex) { LOG.error(ex); } break; case DELETE: FileUtils.deleteQuietly(src); break; case MOVE: File mvDest = new File(baseDir, em.getDestinationPath()); try { FileUtils.moveDirectoryToDirectory(src, mvDest, true); } catch (IOException ex) { LOG.error(ex); } break; case COPY: File cpDest = new File(baseDir, em.getDestinationPath()); try { FileUtils.copyDirectoryToDirectory(src, cpDest); } catch (IOException ex) { LOG.error(ex); } break; default: LOG.error("Unknown change type"); } }
From source file:org.interreg.docexplore.datalink.fs2.DeleteFS2BooksAction.java
public void doAction() throws Exception { File root = ((DataLinkFS2) link.getLink()).getFile(); for (Book book : books) { File bookDir = BookFS2.getBookDir(root, book.getId()); FileUtils.moveDirectoryToDirectory(bookDir, cacheDir, true); link.books.remove(book.getId()); }/* w w w . j av a 2 s .c o m*/ }