file - How to detect if a filename exists (with any extension) in android -
i want return true if filename exists regardless extension. using following method:
file file = new file(environment.getexternalstoragedirectory() + images/","filename.*"); if(file.exists()) { return true; }
there jpg file in directory, if search "filename.jpg", returns true, in case of "filename.*" returns false.
is there way return true if filename same extension?
try
file imagefolder = new file(environment.getexternalstoragedirectory() + "images/"); file[] listoffiles = imagefolder.listfiles(); (file file : listoffiles) { if (file.isfile()) { string[] filename = file.getname().split("\\.(?=[^\\.]+$)"); //split filename it's extension if(filename[0].equalsignorecase("filename")) // file exists ever want } }
Comments
Post a Comment