I want to create directories automatically on my SDCard with given path which contains complete path for a file. the path is coming dynamically from a server so I don't know what are the names of the directories are and how many deep is the directory structure is.
e.g. dir1/dir2/dir3/file1.txt
I am using the following piece of code
createDirectoryIfNotPresent(Environment.getExternalStorageDirectory() + "/"+ mypaths.getNextPath());
where definition of
createDirectoryIfNotPresent
is
private void createDirectoryIfNotPresent(String fileName) {
File f = new File(fileName);
if(!f.exists())
f.mkdirs();
}
but the above code creates directory for file1.txt as well. How do I avoid this? I just want to create directories for directory names and not for filenames.