Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

mkdir() doesn't create sub directories

Thread view: 
carlbernardi@gmail.com - 06 Nov 2006 03:09 GMT
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

:)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.