Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete nested folder in JSP?

Posted on 2002-07-01
6
Medium Priority
?
350 Views
Last Modified: 2010-07-27
How to delete a nested folder that contains files/sub folders in JSP?

thanks.
0
Comment
Question by:trowa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:mraible
ID: 7121845
Same way you would in java.

Look at java.io.File in the Javadocs.

http://java.sun.com/j2se/1.3/docs/api/java/io/File.html

You should be able to delete a file or directory with the "delete" method.
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 200 total points
ID: 7121885
I found this in a FAQ:

public void nuke(File path)
   throws IOException
{
   File[] files = path.listFiles();

   for(int i=0; i<files.length; ++i)
   {
      if(files[i].isDirectory())
         nuke(files[i]);

      files[i].delete();
   }
}

its pretty much a recursive method that will delete a directory and all its files and sub-dirs.

call it using:
nuke("/path/to/dir/to/delete");

HTH,
CJ
0
 

Author Comment

by:trowa
ID: 7126368
CJ, thanks again. The nuke function above work well, but it didn't delete the folder itself. Let's say:

i call nuke("\a");

all the sub-folder and files in a folder is deleted, but the a folder itself is not deleted.

Maybe you can show me how to delete the a folder also inside the Nuke function above.

and why when i compare a String value, i must use:

if (strvalue.equals("abc")) {
//
}

but not if (strvalue == "abc") {
//
}

?

Is this the syntax of Java? what's their difference?

Thanks :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:cheekycj
ID: 7127040
you can just after you call the nuke function do this:

nuke(path);
File dirToDelete = new File(path);
path.delete();

string1.equals(string2) or even
string1.equalsIgnoreCase(string2) are the way to compare strings in java b/c the String object has those methods implemented to compare the values whereas the "==" operator on Objects (Strings are Objects) compares if the two objects are pointing to the same memory reference.  Big Difference :-)

Here is a good link that explains this:
http://www.michael-thomas.com/java/javacert/JCP_ObjectEqual.htm

HTH,
CJ

0
 

Author Comment

by:trowa
ID: 7131361
Thanks a lot again, CJ :)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7131762
Glad I could help and Thanx for the "A".

CJ
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question