Solved

Create directory/folder using JSP?

Posted on 2002-06-08
10
5,469 Views
Last Modified: 2007-11-27
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
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
  • 6
  • 4
10 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 7065457
check out the File i/o tutorials here:
http://www.jspin.com/home/tutorials/filemani
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7075680
did that link help or do you need specific code?

CJ
0
 

Author Comment

by:trowa
ID: 7077615
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!

 
LVL 19

Accepted Solution

by:
cheekycj earned 75 total points
ID: 7078576
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
 

Author Comment

by:trowa
ID: 7109941
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 7110299
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
 

Author Comment

by:trowa
ID: 7115822
Thanks CJ, will try later.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7117387
ok, let me know how it works out.

CJ
0
 

Author Comment

by:trowa
ID: 7121373
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 7121843
I will try :-)

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
difference between member and local variables. 29 150
grep code 4 217
spring JDBC Template example error 26 366
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
Invest in your employees with these five simple steps to improve employee engagement and retention.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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