Solved

Delete nested folder in JSP?

Posted on 2002-07-01
6
347 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 50 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 152
gZip compression filter 2 190
approach on java challenges Approach on java challenges or real world challenges 29 163
throw exception 21 78
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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