Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through a specified directory in Android

i am trying to develop a security application on Android and i want to iterate through the filenames of a specific directory so that i can compare the hash value of each file in the directory.

I have already found out how to do the hashing but for the iterating part i am confused on how it works.

like image 255
dythe Avatar asked Sep 07 '12 01:09

dythe


1 Answers

You mean you want to traverse a directory recursively?

Something like this:

    public void traverse (File dir) {
       if (dir.exists()) {
        File[] files = dir.listFiles();
        if (files != null) {

        for (int i = 0; i < files.length; ++i) {
            File file = files[i];
            if (file.isDirectory()) {
                traverse(file);
            } else {
                // do something here with the file
            }
        }
      }
     }
    } 
like image 87
neevek Avatar answered Oct 28 '22 05:10

neevek