private boolean copyFiles(File destDir) { String[] filesToScan = new String[fileArray.size()]; int numOfFilesToScan = 0; Iterator<File> e = fileArray.iterator(); while (e.hasNext()) { File file = (File) e.next(); File dest = new File(destDir.getAbsolutePath() + "/" + file.getName()); /* FIXME smart renaming and copy force. */ Log.i("gallorg", "copy " + file.getAbsolutePath() + " to " + dest.getAbsolutePath()); if (copyFile(file, dest)) { Log.i("gallorg", "copyFile returns true."); filesToScan[numOfFilesToScan++] = dest.getAbsolutePath(); } else { Log.e("gallorg", "copyFile returns false."); Toast.makeText(this, "Copy Failed! " + dest.getAbsolutePath(), Toast.LENGTH_SHORT).show(); } } Log.i("gallorg", "media scanning..."); if (numOfFilesToScan > 0) { Log.i("gallorg", Integer.toString(numOfFilesToScan) + " files will be scaned."); MediaScanner scanner = new MediaScanner(this); scanner.scanFile(filesToScan); } return true; }
private boolean moveFiles(File destDir) { String[] filesToScan = new String[fileArray.size()]; int numOfFilesToScan = 0; Iterator<File> e = fileArray.iterator(); while (e.hasNext()) { File file = (File) e.next(); File dest = new File(destDir.getAbsolutePath() + "/" + file.getName()); Log.i("gallorg", "rename " + file.getAbsolutePath() + " to " + dest.getAbsolutePath()); if (file.renameTo(dest)) { Log.i("gallorg", "renameTo returns true."); filesToScan[numOfFilesToScan++] = dest.getAbsolutePath(); } else { Log.e("gallorg", "renameTo returns false."); /* FIXME: some error message here! */ } } Log.i("gallorg", "media scanning..."); if (numOfFilesToScan > 0) { Log.i("gallorg", Integer.toString(numOfFilesToScan) + " files will be scaned."); MediaScanner scanner = new MediaScanner(this); scanner.scanFile(filesToScan); } return true; }