3

How I can get files list of certain folder in expension apk file? For assets I did it with:

String[] filesList = getAssets().list("some/path");

But for APK expension file I have only

getExpansionFile().getAllEntries();

which retreive all files. But I need to move around folder, for example move to folder1, show files that place inside. And next move to subfolder1 (which place in folder1) and show fileslist there. I can't it hardcode, becouce files might be changed.

And again: how I can retreive files of certain folder in apk expension file?

IliaEremin
  • 3,338
  • 3
  • 26
  • 35

1 Answers1

2

Finally, I wrote my own implementation.

public class FileStructure {

    public final String pathName;
    // or TreeMap if order matter
    public HashMap<String, FileStructure> files; 

    public FileStructure(String path){
        this.pathName = path;
        files = new HashMap<String, FileStructure>();
    }
}

Getting apk expension file entries with java.util.zip.ZipFile:

ZipFile zf = new ZipFile(Environment.getExternalStorageDirectory().getAbsolutePath() 
        + "/Android/obb/" + getPackageName() 
    + "/main.1." + getPackageName() + ".obb");
            Enumeration zipEntries = zf.entries();
            String fname;

            while (zipEntries.hasMoreElements()) {
                fname = ((ZipEntry) zipEntries.nextElement()).getName();
                addToRoot(fname, root);
            }

And parse it with in FileStructure class

private void addToRoot(String fname, FileStructure root) {
    String[] directories = fname.split(File.separator);
    FileStructure current = root;
    for (int i = 0; i < directories.length; i++) {
        if (!current.files.containsKey(directories[i])) {
            current.files.put(directories[i], new FileStructure(directories[i]));
        }
        current = current.files.get(directories[i]);
    }
}

But, I will appreciate, if someone share some better solution or find defect of my implementation!

IliaEremin
  • 3,338
  • 3
  • 26
  • 35