Solved

Delete nested folder in JSP?

Posted on 2002-07-01
6
340 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now