Solved

Create directory/folder using JSP?

Posted on 2002-06-08
10
5,471 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
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

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

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!

Question has a verified solution.

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

With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
The recent Petya-like ransomware attack served a big blow to hundreds of banks, corporations and government offices The Acronis blog takes a closer look at this damaging worm to see what’s behind it – and offers up tips on how you can safeguard your…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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