android - Removing all content of specific folder -


i trying remove content of device folder on hardware press not happening?

here trying:

     @override     public void onbackpressed() {           deletefilefromdirectory();          finish();       }     public void deletefilefromdirectory()     {          file mediastoragedir = new file(                 environment                         .getexternalstoragepublicdirectory(environment.directory_pictures),                 "mycameraapp");           if (mediastoragedir.exists()) {              isdeleted = mediafile.delete();             system.out.println("file deleted :" +isdeleted);//gives false         }         else             system.out.println("directory not exist");     } 

documentation says must empty ... should do?

if path contain file can delete path contain folder folder must empty, first of have delete files folder , delete particular folder.

here sample code.

public void deleterecursive(string strpath) {      file fileordirectory = new file(strpath);      if (fileordirectory.isdirectory()){         (file child : fileordirectory.listfiles())             deleterecursive(child.getpath());         fileordirectory.delete();     }else{          fileordirectory.delete();     } } 

just call method , pass sdcard path in parameter.

string path = environment.getexternalstoragepublicdirectory(environment.directory_pictures)+"mycameraapp";  deleterecursive(path); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -