mkdir() doesn't create sub directories

mkdir() doesn't create sub directories

Post by carlbernar » Tue, 07 Nov 2006 12:09:48


Hi,

I have been trying to create sub directories with mkdir() and mkdirs()
but both methods fail every time. For example, if I have "c:\\a\b\c\"
already existing, it won't to create "c:\\a\b\c\ddddd". Does anyone
know how I can to get the last subdirectory and create a new one there?
Or even other solutions?


Thanks,
Carl
 
 
 

mkdir() doesn't create sub directories

Post by Andrew Tho » Tue, 07 Nov 2006 15:03:06


...

File methods also work for directories (generally) so
getName() and getParent() should help there.

OTOH, it is bad practice to create directory *structures* as
Strings, and you are probably better off having each
sub-directroy name in an array and looping through it to use..

File root..
for (int ii=0; ii<dirs.length; ii++) {
root = new File(root, dirs[ii]);
}

..this way, the JVM takes care of the separators,
appropriate to the platform.

Andrew T.

 
 
 

mkdir() doesn't create sub directories

Post by Luc The Pe » Tue, 07 Nov 2006 15:41:40


"c:\\a\b\c\ddddd" ?

You mean

"c:\\a\\b\\c\\ddddd" ?

Use forward slashes.

:)