Q:

Java - Strange directory problem?

When I run a class with the following code:
public static void main(String[] args)
{
    createDuplicateStructure("in", "out");
}

public static void createDuplicateStructure(String path_start, String path_result)
{
    File start = new File(path_start);
    File result = new File(path_result);
    duplicateDirectoryStructure(start, result);
}

public static void duplicateDirectoryStructure(File start_dir, File result_dir)
{
    //FileFilter used by listFiles(filter) - to make sure they are dirs
    FileFilter dirs_only = new FileFilter() 
            { 
                public boolean accept(File file){  return file.isDirectory();} 
            };
    File[] dir_contents = start_dir.listFiles(dirs_only);
    for(File dir : dir_contents)
    {
        File duplicate = new File(result_dir.getPath(), dir.getName());
        if(dir.mkdir())
        {
            duplicateDirectoryStructure(dir, duplicate);
        }
        else
        {
            System.out.println("ERROR: Unable to create dir! (" + duplicate.getPath() + ")");
        }
    }
}

I get this in the console:
 Error: Unable to create dir! (out/a)
 Error: Unable to create dir! (out/a)
 Error: Unable to create dir! (out/a)

The directory "out" is in the same directory as the .jar.
There is a directory "in" which contains "a", "b", and "c" directories (for testing).
Any ideas why this is not working?
Thanks!

A:

You should replace dir.mkdir() with duplicate.mkdir() because dir is the already existing source directory.

A:

dir.mkdir() only returns true the directory was actually created. Try doing 
if(dir.mkdir() || dir.exists())

