List of usage examples for java.io File list
public String[] list()
From source file:Main.java
public static void debugLsDir(String dir) { File directory = new File(dir); Log.d("quran_dbg", directory.getAbsolutePath()); if (directory.isDirectory()) { String[] children = directory.list(); for (String s : children) debugLsDir(dir + File.separator + s); }/* ww w. j av a 2 s . c o m*/ }
From source file:Main.java
static private void addFolderToZip(String path, File srcFolder, ZipOutputStream zip, String destZipFile) throws Exception { for (String fileName : srcFolder.list()) { if (path.equals("")) { addFileToZip("/", new File(srcFolder, fileName), zip, destZipFile); } else {/* w w w . j av a 2 s .co m*/ addFileToZip(srcFolder.getName(), new File(srcFolder, fileName), zip, destZipFile); } } }
From source file:Main.java
public static void copy(String source, String target, boolean isFolder) throws Exception { if (isFolder) { (new File(target)).mkdirs(); File a = new File(source); String[] file = a.list(); File temp = null;//from w w w. j a v a 2 s .c om for (int i = 0; i < file.length; i++) { if (source.endsWith(File.separator)) { temp = new File(source + file[i]); } else { temp = new File(source + File.separator + file[i]); } if (temp.isFile()) { FileInputStream input = new FileInputStream(temp); FileOutputStream output = new FileOutputStream(target + "/" + (temp.getName()).toString()); byte[] b = new byte[1024]; int len; while ((len = input.read(b)) != -1) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } if (temp.isDirectory()) { copy(source + "/" + file[i], target + "/" + file[i], true); } } } else { int byteread = 0; File oldfile = new File(source); if (oldfile.exists()) { InputStream inStream = new FileInputStream(source); File file = new File(target); file.getParentFile().mkdirs(); file.createNewFile(); FileOutputStream fs = new FileOutputStream(file); byte[] buffer = new byte[1024]; while ((byteread = inStream.read(buffer)) != -1) { fs.write(buffer, 0, byteread); } inStream.close(); fs.close(); } } }
From source file:com.storageroomapp.client.util.FileUtil.java
static public void deleteFileTree(File file) { if (file.isDirectory()) { if (file.list().length == 0) { file.delete();/* ww w. j a v a 2 s . com*/ } else { String files[] = file.list(); for (String cur : files) { File fileDelete = new File(file, cur); deleteFileTree(fileDelete); } if (file.list().length == 0) { file.delete(); } } } else { file.delete(); } }
From source file:Main.java
private static boolean deleteDir(File dir) { if (dir == null) { return false; }/*from w ww . j a va 2 s . co m*/ if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } } return dir.delete(); }
From source file:com.collaide.fileuploader.helper.TestHelper.java
private static void clean() { File index = new File(getTestCopyDir()); String[] entries = index.list(); for (String s : entries) { File currentFile = new File(index.getPath(), s); currentFile.delete();//ww w . jav a 2 s . c o m } }
From source file:Main.java
public static void copyDirectory(File srcDir, File dstDir) throws IOException { if (srcDir.isDirectory()) { if (!dstDir.exists()) { dstDir.mkdir();//from w w w . ja v a 2 s. com } String[] children = srcDir.list(); for (int i = 0; i < children.length; i++) { copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i])); } } else { copyFile(srcDir, dstDir); } }
From source file:Main.java
public static void copyDirectory(File srcDir, File dstDir) throws IOException { if (srcDir.isDirectory()) { if (!dstDir.exists()) { dstDir.mkdir();/*from w w w .ja v a 2s.c om*/ } String[] children = srcDir.list(); for (int i = 0; i < children.length; i++) { copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i])); } } else { copyFile(srcDir, dstDir); } }
From source file:de.uzk.hki.da.utils.FolderUtils.java
public static List<String> listFolderContents(File folder) { String[] fileNames = folder.list(); List<String> fileList = new ArrayList<String>(); for (String fileName : fileNames) { if (new File(folder.getAbsolutePath() + "/" + fileName).isDirectory()) { List<String> folderFileNames = listFolderContents( new File(folder.getAbsoluteFile() + "/" + fileName)); for (String folderFileName : folderFileNames) fileList.add(fileName + "/" + folderFileName); } else/* w w w . j a va2s .co m*/ fileList.add(fileName); } return fileList; }
From source file:DuplicatedMusicCleaner.java
public static void cleanupFolder(File folder) throws IOException { // System.out.println("Evaluate " + folder.getAbsolutePath()); String[] fileNames = folder.list(); Map<String, String> fileNamesWithoutExtension = new HashMap<String, String>(); for (String fileName : fileNames) { File file = new File(folder, fileName); String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), "."); fileNamesWithoutExtension.put(nameWithoutExtension, file.getAbsolutePath()); }/*from w w w . ja v a 2 s . c o m*/ for (String fileName : fileNames) { // System.out.println("Evaluate " + fileName); File file = new File(folder, fileName); if (file.isDirectory()) { cleanupFolder(file); } else { String nameWithoutExtension = StringUtils.substringBeforeLast(file.getName(), "."); String suffix = " 1"; if (nameWithoutExtension.endsWith(suffix)) { String nameWithoutSuffix = StringUtils.substringBeforeLast(nameWithoutExtension, suffix); if (fileNamesWithoutExtension.keySet().contains(nameWithoutSuffix)) { File originalFile = new File(fileNamesWithoutExtension.get(nameWithoutSuffix)); long originalFileLength = originalFile.length(); long fileLength = file.length(); if (originalFileLength == fileLength) { System.err.println("Delete " + file.getName()); FileUtils.deleteQuietly(file); // FileUtils.moveFile(file, new // File(file.getAbsoluteFile() + ".todelete")); } } } /* * if(file.getName().endsWith(".todelete")) { String newFileName * = StringUtils.substringBeforeLast(file.getName(), * ".todelete"); File parent = file.getParentFile(); File * parentParent = parent.getParentFile(); newFileName = * parentParent.getName() + "_" + parent.getName() + "_" + * newFileName; * * File target = new File("/Users/cyrilleleclerc/todelete", * newFileName); System.out.println(target); * FileUtils.moveFile(file, target); * * } */ } } }