顯示具有 File 標籤的文章。 顯示所有文章
顯示具有 File 標籤的文章。 顯示所有文章

2015年5月11日 星期一

[Android] File sort, delete, folder create

Sort:
File[] files = XMLDirectory.listFiles(filter_xml_files);
Arrays.sort(files);
//Arrays.sort(files, Collections.reverseOrder());  //resort
for(File _xml_file : files) {
    ... 
} 
reference: http://stackoverflow.com/questions/7199911/how-to-file-listfiles-in-alphabetical-order


Delete:
File file = new File(selectedFilePath);
boolean deleted = file.delete();
reference: http://stackoverflow.com/questions/1248292/how-to-delete-a-file-from-sd-card


Folder create:
   java.io.File file = new java.io.File(save_path);
   /* if the folder is not exist, create it */
   if (!file.exists())
    file.mkdirs();






2015年5月10日 星期日

[Android] file delete


//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);
  File imgFile = new  File(del_path+children[i]);
  if(imgFile.exists()){
   new File(dir, children[i]).delete();
  }
 } 
} 

[Android] check files is exist or not and then remove files


//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);
  File imgFile = new  File(del_path+children[i]);
  if(imgFile.exists()){
   new File(dir, children[i]).delete();
  }
 } 
} 

2015年5月9日 星期六

[Android] remove files from the specific folder



//remove past thumbnail
String del_path = Environment.getExternalStorageDirectory() + "/Download/IPCam/"+camIDArr[camIndex]+"/thumbnail/";
File dir = new File(del_path); 
Log.e("Environment.getExternalStorageDirectory()+del_path",del_path);
if (dir.isDirectory()) {
 String[] children = dir.list();
 
 for (int i = 0; i < children.length; i++) {
  Log.e("^^^^^^^^^=====>  children["+i+"]",children[i]);     //children[i]   => file name , for example snapshot_20150509140728.jpg
  new File(dir, children[i]).delete();
 } 
}