Solved

Create directory/folder using JSP?

Posted on 2002-06-08
10
5,466 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
  • 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
password protect pdf 11 72
EJB MDB example 4 76
doubleChar java challenge 7 97
How to Post an If Statement in JSP 3 45
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

14 Experts available now in Live!

Get 1:1 Help Now