android - How to show only non-hidden folders programmatically -
so have simple method helps list all of files in directory (hidden and non-hidden) , wish edit display only non hidden files.
public arraylist<string> getfiles(string directorypath) { arraylist<string> myfiles = new arraylist<string>(); file file = new file(directorypath); //you create array list //the public final field length, contains number of components of array file.mkdirs(); file[] files = file.listfiles(); //list of files in array if (files.length == 0) //if there no files, return null return null; else { //if number of files greater 0, add files , names (int = 0; < files.length; i++) myfiles.add(files[i].getname()); } return myfiles;
how can modify above code display non hidden files?
by way, inserting . in front of file name hides file.
thank you.
you should able make use of ishidden()
. refer docs here.
//if number of files greater 0, add files , names (int = 0; < files.length; i++) { if(!files[i].ishidden()) myfiles.add(files[i].getname()); // add non hidden files }
Comments
Post a Comment