【问题标题】:Find files in a folder using android使用android在文件夹中查找文件
【发布时间】:2015-10-03 13:01:17
【问题描述】:

我想做与in this question 相同的操作,但在 Android 上,我想返回完整的文件路径 If it exists= true in EditText ? 我如何以及在何处放置代码

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

获取完整的文件路径

// 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");
    }
});

【问题讨论】:

  • 你想要sd卡的文件路径对吗?
  • 我已经重读了很多遍,但我仍然不明白你的意思。 EditText 与文件路径有什么关系?请慢慢来,想想再想想,然后尝试更清楚地重新表述。
  • 感谢您的评论,我真的很抓紧时间,我再次思考,我得到了我想要的 >>> 感谢您的回复 >> 问候

标签: android


【解决方案1】:

感谢所有我想要的东西。 最好的祝福

        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);}


                    }
                }
            }
        }
    }

}

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多