Example usage for org.apache.commons.io FileUtils moveDirectoryToDirectory

List of usage examples for org.apache.commons.io FileUtils moveDirectoryToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils moveDirectoryToDirectory.

Prototype

public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) throws IOException 

Source Link

Document

Moves a directory to another directory.

Usage

From source file:administraScan.OrganizaDirectorios.java

public boolean clasificar() {
    String ruta = conf.carpetaRemota + "aceptados\\";
    File f = new File(ruta);
    FileUtils Files = new FileUtils();
    String ct = "";
    System.out.println(f.list());
    ArrayList<String> names = new ArrayList<>(Arrays.asList(f.list()));
    if (!names.isEmpty()) {
        for (int i = 0; i < names.size(); i++) {
            System.out.println(names.get(i));
            System.out.println("hay algo");
            ct = obtenerCT(names.get(i));
            if (ct.equals("")) {
                System.out.println("Se acab");

            } else {
                String prueba = (String) (names.get(i).toString());
                System.out.println("" + prueba);
                String rutadestino = conf.carpetaCT + "\\" + names.get(i) + "\\";
                File destino = new File(conf.carpetaCT + ct + "\\" /*+ names.get(i) + "/"*/);
                File origen = new File(ruta + names.get(i) + "\\");
                try {
                    Files.moveDirectoryToDirectory(origen, destino, true);
                    //Aqu se actualiza la variable

                } catch (IOException E) {
                    E.printStackTrace();
                }/*from w  ww  . j  a v  a  2 s. c  o m*/
            }
        }
        resultado = false;
    } else {
        JOptionPane.showMessageDialog(null, "No ningun elemento que mover");
    }
    return resultado;
}

From source file:com.zaradai.bloodstone.file.FileIO.java

@Override
public void moveDirectory(String source, String destination, boolean createDstDir) throws IOException {
    Preconditions.checkNotNull(source, "Invalid source path specified");
    Preconditions.checkNotNull(destination, "Invalid destination path specified");

    FileUtils.moveDirectoryToDirectory(new File(source), new File(destination), createDstDir);
}

From source file:com.gollahalli.manager.FileMover.java

public void forMac(boolean yes) {
    if (yes) {// w ww. j a  va 2 s .co m
        try {
            File f = new File("/Applications/JCal.app/Contents/Java");
            if (f.exists() && f.isDirectory()) {
                FileUtils.deleteDirectory(FileUtils.getFile("/Applications/JCal.app/Contents/Java/lib"));
                FileUtils.deleteQuietly(FileUtils.getFile("/Applications/JCal.app/Contents/Java/JCal.jar"));
            }
            FileUtils.copyDirectoryToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal/lib"),
                    FileUtils.getFile("/Applications/JCal.app/Contents/Java"));
            FileUtils.copyFileToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal/JCal.jar"),
                    FileUtils.getFile("/Applications/JCal.app/Contents/Java"));
        } catch (IOException e) {
        }
    } else {
        try {
            File f = new File("/Applications/JCal.app");
            if (f.exists()) {
                FileUtils.deleteQuietly(FileUtils.getFile("/Applications/JCal.app"));
            }
            FileUtils.moveDirectoryToDirectory(
                    FileUtils.getFile(System.getProperty("user.home") + "/Downloads/JCal.app"),
                    FileUtils.getFile("/Applications/"), false);
        } catch (IOException e) {
        }
    }
}

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/*  ww w.  j a  v  a2s .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:com.aniruddhc.acemusic.player.AsyncTasks.AsyncCopyMoveTask.java

@Override
protected Boolean doInBackground(String... params) {

    try {/*from  ww  w . j  a v a  2  s  . co  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 {/*from  www . j a  v  a  2s.  c  o  m*/
            FileUtils.moveFileToDirectory(aOrigineFile, sDestinationFile.getFile(), true);
        }
    } else {
        FileUtils.moveDirectoryToDirectory(aOrigineFile, sDestinationFile.getFile(), true);
    }
}

From source file:it.geosolutions.geobatch.actions.commons.ExtractAction.java

/**
 * Removes TemplateModelEvents from the queue and put
 *//*from   ww w.  j  a  v  a2s . co 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 extractMultipleFile;
    final int size = events.size();
    if (size == 0) {
        throw new ActionException(this, "Empty file list");
    } else if (size > 1) {
        extractMultipleFile = true;
    } else {
        extractMultipleFile = false;
    }

    final File dest = conf.getDestination();

    if (dest != null && !dest.isDirectory()) {
        if (!dest.mkdirs()) {
            throw new ActionException(this, "bad destination (not writeable): " + dest);
        }
    }

    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();

            try {
                listenerForwarder.setTask("Extracting file: " + source);
                final File extracted = Extract.extract(source, getTempDir(), false);
                if (extracted != null) {
                    if (dest != null) {
                        File newDest = new File(dest, extracted.getName());
                        listenerForwarder.setTask("moving \'" + extracted + "\' to \'" + newDest + "\'");
                        FileUtils.moveDirectoryToDirectory(extracted, newDest, true);
                        listenerForwarder.terminated();
                        ret.add(new FileSystemEvent(newDest, FileSystemEventType.DIR_CREATED));
                    } else {
                        throw new ActionException(this, "Unable to extracto file: " + source);
                    }
                } else {
                    final String message = "Unable to extract " + source;
                    if (!getConfiguration().isFailIgnored()) {
                        ActionException ex = new ActionException(this.getClass(), message);
                        listenerForwarder.failed(ex);
                        throw ex;
                    } else {
                        LOGGER.warn(message);
                    }
                }
            } catch (Exception e) {
                final String message = "Unable to copy extracted archive";
                if (!getConfiguration().isFailIgnored()) {
                    ActionException ex = new ActionException(this.getClass(), message);
                    listenerForwarder.failed(ex);
                    throw ex;
                } else {
                    LOGGER.warn(e.getLocalizedMessage());
                }

            }
        } else {
            final String message = "Incoming instance is not a FileSystemEvent: " + event;
            if (!getConfiguration().isFailIgnored()) {
                ActionException ex = new ActionException(this.getClass(), message);
                listenerForwarder.failed(ex);
                throw ex;
            } else {
                LOGGER.warn(message);
            }
        }
        // TODO setup task progress
    } // endwile

    listenerForwarder.completed();
    return ret;
}

From source file:com.sangupta.snowpack.SnowpackRecover.java

/**
 * Rename any previous metadata directory to show that it is pre-recovery.
 * /*w w w  .j a v a2 s  . com*/
 * @param baseDirectory
 * @throws IOException 
 */
private static void renameOldMetadataDirectory(File baseDirectory) throws IOException {
    File dir = new File(baseDirectory, SnowpackConstants.SNOWPACK_METADATA_DIRECTORY);
    File preRecover = new File(baseDirectory,
            SnowpackConstants.SNOWPACK_METADATA_DIRECTORY + ".prerecover." + System.currentTimeMillis());
    if (dir.exists() && dir.isDirectory()) {
        FileUtils.moveDirectoryToDirectory(dir, preRecover, true);
    }
}

From source file:de.uzk.hki.da.cb.UnpackAction.java

private void moveSipDir() throws IOException {
    FileUtils.moveDirectoryToDirectory(wa.sipFile(), wa.objectPath().toFile(), true);
}

From source file:it.greenvulcano.util.file.FileManager.java

/**
 * Move a file/directory on the local file system.<br>
 *
 * @param oldPath/*from ww w  .  j  a  va 2 s  .c o m*/
 *            Absolute pathname of the file/directory to be renamed
 * @param newPath
 *            Absolute pathname of the new file/directory
 * @param filePattern
 *            A regular expression defining the name of the files to be copied. Used only if
 *            srcPath identify a directory. Null or "" disable file filtering.
 * @throws Exception
 */
public static void mv(String oldPath, String newPath, String filePattern) throws Exception {
    File src = new File(oldPath);
    if (!src.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the source is NOT absolute: " + oldPath);
    }
    File target = new File(newPath);
    if (!target.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the destination is NOT absolute: " + newPath);
    }
    if (target.isDirectory()) {
        if ((filePattern == null) || filePattern.equals("")) {
            FileUtils.deleteQuietly(target);
        }
    }
    if (src.isDirectory()) {
        if ((filePattern == null) || filePattern.equals("")) {
            logger.debug("Moving directory " + src.getAbsolutePath() + " to " + target.getAbsolutePath());
            FileUtils.moveDirectory(src, target);
        } else {
            Set<FileProperties> files = ls(oldPath, filePattern);
            for (FileProperties file : files) {
                logger.debug("Moving file " + file.getName() + " from directory " + src.getAbsolutePath()
                        + " to directory " + target.getAbsolutePath());
                File finalTarget = new File(target, file.getName());
                FileUtils.deleteQuietly(finalTarget);
                if (file.isDirectory()) {
                    FileUtils.moveDirectoryToDirectory(new File(src, file.getName()), finalTarget, true);
                } else {
                    FileUtils.moveFileToDirectory(new File(src, file.getName()), target, true);
                }
            }
        }
    } else {
        if (target.isDirectory()) {
            File finalTarget = new File(target, src.getName());
            FileUtils.deleteQuietly(finalTarget);
            logger.debug("Moving file " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath());
            FileUtils.moveFileToDirectory(src, target, true);
        } else {
            logger.debug("Moving file " + src.getAbsolutePath() + " to " + target.getAbsolutePath());
            FileUtils.moveFile(src, target);
        }
    }
}