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 6247467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:52:37+00:00 2026-05-24T12:52:37+00:00

ANSWER: Needed the call to getExternalFilesDir(p); like so: String p = thepathblah; File path=context.getExternalFilesDir(p);

  • 0

ANSWER:

Needed the call to getExternalFilesDir(p); like so:

String p = thepathblah; 
File path=context.getExternalFilesDir(p);

EDIT EDIT:

While I knew the Environment.DIRECTORY_PICTURES was returning just Pictures/ I figured this worked because in android I assumed the file pointer was already pointing to your application space (sorta like in c#). So in this:

 String p = Environment.DIRECTORY_PICTURES + "/" + s.getClient().getFirstName()+s.getClient().getLastName() +
 "/" + s.getPackage().getName() +
 (mSession.getSessionDate().getMonth()+1)  +  
 mSession.getSessionDate().getDate() +  
  (mSession.getSessionDate().getYear()+1900);

I thought was getting the full path, in fact I was writing a file out to this with no issues. It turns out though to delete individual files (and load them) I needed a fuller path which ended up being:

 String p = Environment.DIRECTORY_PICTURES + "/" + s.getClient().getFirstName()+s.getClient().getLastName() +
 "/" + s.getPackage().getName() +
 (mSession.getSessionDate().getMonth()+1)  +  
 mSession.getSessionDate().getDate() +  
  (mSession.getSessionDate().getYear()+1900);

 File dir = new File("/sdcard/Android/data/com.software.oursoftware/files/"+p);

Not sure if I can take it that the above link is valid for all Honeycomb devices or not, specifically the /sdcard/Android/data/packagespace/files/

Is this safe to use this or do I have to do something more dynamic for honeycomb devices???

EDIT: This is my little test function code to just write something to a folder…

   String p = Environment.DIRECTORY_PICTURES + "/" + s.getClient().getFirstName()+s.getClient().getLastName() + "/" + s.getPackage().getName() + (mSession.getSessionDate().getMonth()+1)  +  mSession.getSessionDate().getDate() + (mSession.getSessionDate().getYear()+1900);
            File path = mContext.getExternalFilesDir(p);
            File file = new File(path, "DemoPicture.jpg");

            try {
                // Very simple code to copy a picture from the application's
                // resource into the external file.  Note that this code does
                // no error checking, and assumes the picture is small (does not
                // try to copy it in chunks).  Note that if external storage is
                // not currently mounted this will silently fail.
                InputStream is = getResources().openRawResource(R.drawable.ic_contact_picture);
                OutputStream os = new FileOutputStream(file);
                byte[] data = new byte[is.available()];
                is.read(data);
                os.write(data);
                is.close();
                os.close();

                // Tell the media scanner about the new file so that it is
                // immediately available to the user.
                MediaScannerConnection.scanFile(mContext,
                        new String[] { file.toString() }, null,
                        new MediaScannerConnection.OnScanCompletedListener() {
                    public void onScanCompleted(String arg0, Uri arg1) {
                         Log.i("ExternalStorage", "Scanned " + arg0 + ":");
                            Log.i("ExternalStorage", "-> uri=" + arg1);

                    }
                });
            } catch (IOException e) {
                // Unable to create file, likely because external storage is
                // not currently mounted.
                Log.w("ExternalStorage", "Error writing " + file, e);
            }

Then the way I try to delete this folder:

String p = Environment.DIRECTORY_PICTURES + "/" + firstName+lastName +"/" + pName+pDate;
File dir=new File(p); 
deleteRecursive(dir);

results in

Pictures/ShaneThomas/Portrait882011/

Which can write a file, tested that, but if I try to say:

void deleteRecursive(File dir)
{
    Log.d("DeleteRecursive", "DELETEPREVIOUS TOP" + dir.getPath());
    if (dir.isDirectory())
    {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) 
        {
           File temp =  new File(dir, children[i]);
           if(temp.isDirectory())
           {
               Log.d("DeleteRecursive", "Recursive Call" + temp.getPath());
               deleteRecursive(temp);
           }
           else
           {
               Log.d("DeleteRecursive", "Delete File" + temp.getPath());
               boolean b = temp.delete();
               if(b == false)
               {
                   Log.d("DeleteRecursive", "DELETE FAIL");
               }
           }
        }

        dir.delete();
    }
}

The dir.isDirectory is always false!? I got this delete file/directories code off stack overflow but am puzzled as to why its not working?

and I do have this set:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  • 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-24T12:52:40+00:00Added an answer on May 24, 2026 at 12:52 pm

    I think you want to add

    dir.mkdirs() right after File dir=new File(p). mkdirs() is the method responsible for actually creating a directory, not new File().

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

Sidebar

Related Questions

I have googled this a little and didn't really find the answer I needed.
ANSWER: If you ever see these lines and are mistified like I was, here's
Answer : Implemented using Curl... $file = http://abc.com/data//output.txt; $ch = curl_init($file); $fp = @fopen(out.txt,
Sorry answer found while typing I am trying to connect to an external webservice
This question came into my mind while generating sample data for a SO-answer. I
I call an external program inside a function. Now i would like to timeout
This answer says that Linq is targeted at a slightly different group of developers
An answer to a Stack Overflow question stated that a particular framework violated a
In answer to this question Joel Coehoorn said Finally, only after the site's gone
An answer to one of my questions included the following line of code: label

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.