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
Andrew Thompson - 06 Nov 2006 06:03 GMT
...
> 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?
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.
Luc The Perverse - 06 Nov 2006 06:41 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> know how I can to get the last subdirectory and create a new one there?
> Or even other solutions?
"c:\\a\b\c\ddddd" ?
You mean
"c:\\a\\b\\c\\ddddd" ?
Use forward slashes.
--
LTP
:)