Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Delete a Directory

 
Abdul Salam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any reliable way of deleting a directory
and it's contents from java (recursively).
I have tried

It also did not work.My OS is win 2000 server.
Thx in advance.
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think u'll have to delete it thro' coding methods.U can write a method that accepts the directory path,using this delete the files of the current directory ,in case of sub-folders call this funtion recursively with the sub-folder path.This is the way I know.
Happy middling with java.
Netharam.
 
etrivelli nainar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, can we delete a file using java I/O?
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netharam's right. You have to delete all the files in the directory before deleting the directory itself. The methods in the File class isDirectory(), listFiles(), and delete() should be all you need.
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FAQ: How do I delete a directory that isn't empty?
http://www.jguru.com/faq/view.jsp?EID=705646
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic