Java File Path Delete deleteWallpaper(String file_name, Map dimmensions, String basepath, List resolution_directories)

Here you can find the source of deleteWallpaper(String file_name, Map dimmensions, String basepath, List resolution_directories)

Description

deletes a wallpaper and all its copies

License

Apache License

Parameter

Parameter Description
wallpaper Wallpaper object
dimmensions map that contains name(folder)/resolution of resized wallpaper
basepath path of folder where to look for subdirectories
resolution_directories directories for wallpapers resized to user resolutions

Declaration

public static boolean deleteWallpaper(String file_name,
        Map<String, Integer> dimmensions, String basepath,
        List<File> resolution_directories) 

Method Source Code

//package com.java2s;
/*// ww  w.  j a  v  a2 s .co m
 *  Copyright 2010 demchuck.dima@gmail.com
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.File;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Main {
    /**
     * deletes a wallpaper and all its copies
     * @param wallpaper Wallpaper object
     * @param dimmensions map that contains name(folder)/resolution of resized wallpaper
     * @param basepath path of folder where to look for subdirectories
     * @param resolution_directories directories for wallpapers resized to user resolutions
     * @return
     */
    public static boolean deleteWallpaper(String file_name,
            Map<String, Integer> dimmensions, String basepath,
            List<File> resolution_directories) {
        Set<Entry<String, Integer>> entrySet = dimmensions.entrySet();
        Iterator<Entry<String, Integer>> entries = entrySet.iterator();
        while (entries.hasNext()) {
            Entry<String, Integer> e = entries.next();
            File rez = new File(basepath + File.separator + e.getKey()
                    + File.separator + file_name);
            if (rez.exists() && !rez.delete()) {
                rez.deleteOnExit();
                //one file exists but is not deleted error here :(
                // may be its better try to delete other copies ...
                return false;
            }
        }
        for (File f : resolution_directories) {
            File image = new File(f, file_name);
            if (image.exists() && !image.delete()) {
                image.deleteOnExit();
            }
        }
        return true;
    }
}

Related

  1. deleteSubfiles(String publishTemppath)
  2. deleteTemp(String tempPath)
  3. deleteTempDataFile(String dataFilePath)
  4. deleteTempFile(String sourceFilePath)
  5. deleteTree(final File path)
  6. delFile(String filePath)
  7. delFile(String filePath, String fileName)
  8. delFile(String filePathAndName)
  9. delFile(String filePathAndName)