-2

I want to do the same as in this question but on Android, and I want to return the full file path If it exists= true in EditText ? How and where I put the code

EditText txt11 = (EditText) findViewById(R.id.editText11);
txt11.setText(ss2 , TextView.BufferType.EDITABLE);

to get the full file path

// your directory
File f = new File("C:\\example");
File[] matchingFiles = f.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.startsWith("temp") && name.endsWith("txt");
    }
});
Community
  • 1
  • 1
TARIQ ALEED
  • 69
  • 3
  • 11
  • you want path of file from sd card right? – Anand Singh Jul 14 '15 at 18:18
  • 1
    I've reread that multiple times now and I still don't get what you mean. How is the EditText related to the filepath? Please take your time, *think*, *think again*, then try to rephrase more clearly. – runDOSrun Jul 14 '15 at 18:23
  • Thank you for your comment,I am really i take my time, and i think Again and i get what I want >>> thank you for your response >> Greetings – TARIQ ALEED Jul 15 '15 at 08:15

1 Answers1

0

Thank for all I've got what I want. Best wishes

        File f = new File(Environment.getExternalStorageDirectory().getPath() + "/image1/Original_Images/" );
        getAllFilesOfDir(f);
}

    private void getAllFilesOfDir(File directory) {
        EditText txt12 = (EditText) findViewById(R.id.editText12);
        EditText txt10 = (EditText) findViewById(R.id.editText10); // We have this IN  editText10 = "_20151.jpg"
                                     //  /storage/sdcard0/image1/Original_Images/TARIQ_20151.jpg"  We want to find TARIQ
        final File[] files = directory.listFiles();

        if ( files != null ) {
            for ( File file : files ) {
                if ( file != null ) {
                    if ( file.isDirectory() ) {  // it is a folder...
                        getAllFilesOfDir(file);
                    }
                    else {  // it is a file...
                      String  str2=file.getAbsolutePath();
                        String  str3=file.getAbsolutePath();

                        int start = str2.toString().trim(). lastIndexOf("_");
                        String suffix =  str2.toString().trim().substring(start );


if(suffix.toString().trim().equals(txt10.getText().toString().trim())){

    int start2 = str3.toString().trim(). lastIndexOf("/");
    int end2 = str3.toString().trim(). lastIndexOf("_");
    String suffix2 =  str2.toString().trim().substring(start2+1,end2);


    txt12.setText( suffix2.toString().trim() , TextView.BufferType.EDITABLE);
return;


}    else { txt12.setText(null  , TextView.BufferType.EDITABLE);}


                    }
                }
            }
        }
    }

}
TARIQ ALEED
  • 69
  • 3
  • 11