0

I'm trying to create an empty directory, but instead it creates a file.

publicDocsPath = 
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);

autoTestDir = new File(publicDocsPath + File.separator+"autoTest");        
autoTestDir.mkdirs();

I can get around it by creating a dummy file under neath it, as such

autoTestDir = new File(publicDocsPath + File.separator+"autoTest" + File.separator+ "nullfile");

But I would like to know if I'm doing something wrong or if there is a way to tell the system you want to create a directory not a file.

Note: I'm on a mac, and I'm using Android File Transfer program to verify my results. Maybe the file is being created as a directory, but issue is with Android File Transfer and it shows the directory as a file.

Siavash
  • 7,583
  • 13
  • 49
  • 69

1 Answers1

0

Try this

File documents = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
File dir = new File(documents.getAbsolutePath() + File.separator + "autoTest" + File.separator);

// creates if doesn't exists
dir.mkdir();

You have to add the file separator after "autoTest".

Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67