[개발] 안드로이드 SD카드 내 폴더 및 하위 파일 일괄삭제 브랜든정 2011. 7. 20. 18:07 반응형 SD 메모리 내에 있는 파일 및 폴더 삭제 함수 public static boolean deleteFolder(Context context, File targetFolder){ if(!targetFolder.exists()) return false; File[] childFile = targetFolder.listFiles(); boolean confirm = false; int size = childFile.length; if(size > 0){ for(int i=0; i<size; i++){ if(childFile[i].isFile()){ confirm = childFile[i].delete(); } else{ deleteFolder(context, childFile[i]); } } } targetFolder.delete(); Toast.makeText(context, "Cleaned all cache successfully!!!", Toast.LENGTH_SHORT).show(); return (!targetFolder.exists()); } 사용하는 방법은, String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath(); File dir = new File(sdPath + "/targetFolder"); // delete all cache deleteFolder(this, dir); 참조: http://holamiamor.tistory.com/289 반응형