• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5476
  • Last Modified:

Create directory/folder using JSP?

How to create a directory/folder in my website using JSP?

What is mean by System.getProperty("survey.dir")? How do i determine whether a directory is exist or not, if not then create a new directory.

Thanks.
0
trowa
Asked:
trowa
  • 6
  • 4
1 Solution
 
cheekycjCommented:
check out the File i/o tutorials here:
http://www.jspin.com/home/tutorials/filemani
0
 
cheekycjCommented:
did that link help or do you need specific code?

CJ
0
 
trowaAuthor Commented:
Thanks CJ, but which one should i try? The code there is just complicated for me! Yes, i do need specific code, 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!

 
cheekycjCommented:
Here is basic code:

<%@ page import="java.io.*,java.io.File" %>
<%
     File dir = new File("path/to/directory");
     if (dir.exists()) {
          if (dir.isDirectory()) {
               // path exists and is a directory
          }
          else {
               // path does exist but is not a directory -- probably just a file
          }
     }
     else {
          // path does not exist so create directory
          if (dir.mkdir()) {
               // directory creation successful
          }
          else {
               // directory creation unsuccessful
          }
     }
%>
0
 
trowaAuthor Commented:
Hi CJ,

The code above working well :)

Can you do me a favour? How can i delete the folder? :P

Of course points will be added for your contributions.

Thanks a lot.
0
 
cheekycjCommented:
if the directory is empty its simple:

<%@ page import="java.io.*,java.io.File" %>
<%
    File dir = new File("path/to/directory");
    if (dir.exists()) {
         if (dir.isDirectory()) {
              dir.delete();
         }
         else {
              // path does exist but is not a directory -- probably just a file
         }
%>

But if the directory has files you must delete the files in the dir.

HTH,
CJ
0
 
trowaAuthor Commented:
Thanks CJ, will try later.
0
 
cheekycjCommented:
ok, let me know how it works out.

CJ
0
 
trowaAuthor Commented:
Thanks CJ. I will ask another question regarding how to delete a nested folder later. Hope you can take sometime to solve this problem
0
 
cheekycjCommented:
I will try :-)

Glad I could help and Thanx for the "A".

CJ
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now