Here you can find the source of deleteWallpaper(String file_name, Map
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 |
public static boolean deleteWallpaper(String file_name, Map<String, Integer> dimmensions, String basepath, List<File> resolution_directories)
//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; } }