Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7020361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:31+00:00 2026-05-27T23:18:31+00:00

I’m buiding an app that what it does is scan the root folder and

  • 0

I’m buiding an app that what it does is scan the root folder

Assets

and then it searches if there is any folder inside… the purpose of this is to save all the
text files routes in database..the database will contain the textfile name and the route.

this is part of the code:

private void seedData(int indent, File file) throws IOException {
        if (file.isDirectory()) {
          File[] files = file.listFiles();
          for (int i = 0; i < files.length; i++)
            {
              seedData(indent + 4, files[i]);
              path+=files[i].getPath();
            }

        }
        else{
            db.execSQL("insert into "+TABLE+" (title, url) values ('"+
                    file.getName().substring(0, file.getName().length()-4)+"', '"+file.getPath()+"');");
        }

      }

but in normal Java I just create a File with the route and then send it to the method like
this: seedData(1, new File("/root")); .So my question is, how do I do this in Android? or to be more precise, how do I create a file that points to the root folder that is located in assets so it gets “scanned” by my code. I already tried seedData(1, new File("/assets/root")); but it just didnt work.
Any help would be much appreciated.

Note: No, I cannot save the paths manually since there is over 3k text files in all those subfolders.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:18:32+00:00Added an answer on May 27, 2026 at 11:18 pm

    The problem here is that the assets are not files. The Android equivalent of your above method would be something like this:

    private void seedData(int indent, String path, AssetManager mgr)
        throws IOException
    {
        String[] list = mgr.list(path);
        if (list.length > 0) {
            // path is a directory with something in it
            for (String item : list) {
                seedData(indent + 4, path + "/" + item, mgr);
            }
        } else {
            // path is either an empty directory or a file
            // unfortunately, Android makes it hard to distinguish
            String name = path.substring(path.lastIndexOf('/') + 1);
            db.execSQL("insert into "+TABLE+" (title, url) values ('"
                    +name.substring(0, name.length()-4)+"', '"
                    +path+"');");
        }
    }
    

    You would call this from your Activity with

    seedData(0, "root", getAssets());
    

    For reference, the URI format for assets in the “root” folder is file:///android_asset/root/....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.