Java Delete Temp Directory deleteTempMapset(String mapsetFolder)

Here you can find the source of deleteTempMapset(String mapsetFolder)

Description

Deletes the location and mapset(s) for GRASS data processing.

License

Open Source License

Declaration

public static void deleteTempMapset(String mapsetFolder) 

Method Source Code

//package com.java2s;
/*/*  ww  w .j  av a 2 s .  co m*/
 * This file is part of JGrasstools (http://www.jgrasstools.org)
 * (C) HydroloGIS - www.hydrologis.com 
 * 
 * JGrasstools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * Deletes the location and mapset(s) for GRASS data processing.
     */
    public static void deleteTempMapset(String mapsetFolder) {
        if ((mapsetFolder != null) && (mapsetFolder.length() > 2)) {
            String tmpFolder = new String(mapsetFolder.substring(0,
                    mapsetFolder.lastIndexOf(File.separator)));
            if (new File(tmpFolder).exists()) {
                deleteDirectory(new File(tmpFolder));
            }
        }
    }

    private static boolean deleteDirectory(final File path) {
        if (path.exists()) {
            final File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return path.delete();
    }
}

Related

  1. deleteTempDir()
  2. deleteTempDir(File file)
  3. deleteTempDirectories(List lstTempDirectories)
  4. deleteTempDirectory(File dir)
  5. deleteTemporaryDirectory(String dir)
  6. deleteTestData()
  7. deleteTestDir(final File file)
  8. deleteTestDirectory(File testDir)