Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Finding out if a folder exists

Reply
Thread Tools

Finding out if a folder exists

 
 
christopher_board@yahoo.co.uk
Guest
Posts: n/a
 
      02-05-2007
I am currently writing a java application that backs up a directory
and copies it to another location. I want the user to enter the path
of the directory in a JTextField. For example C:\Documents and
Settings. Once the user has entered the path they want to backup they
then click a button which will then check to make sure that, that
directory exists. If it doesn't a message is displayed and if it does
then it performs a certain task. How would I go about checking to make
sure the folder exists.

Thanks very much for your help.

I look forward to hearing from you in the near future.

 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      02-05-2007
In article <(E-Mail Removed) .com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I am currently writing a java application that backs up a directory
> and copies it to another location. I want the user to enter the path
> of the directory in a JTextField. For example C:\Documents and
> Settings. Once the user has entered the path they want to backup they
> then click a button which will then check to make sure that, that
> directory exists. If it doesn't a message is displayed and if it does
> then it performs a certain task. How would I go about checking to make
> sure the folder exists.
>
> Thanks very much for your help.
>
> I look forward to hearing from you in the near future.


First, I think your text field should be accompanied by a button (we use
one labeled Browse in similar situations) that supports selecting
(presumably via JFileChooser) directories only. But once you've got a
selected item, even if manually entered, you want to make a File object
out of it and then call the isDirectory method on that object. This
method will return true if the item actually exists and it's a directory
rather than a file. You may want to see if your target directory can be
written to, also.

I highly recommend the API Javadocs on java.io.File for your reading
pleasure.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      02-05-2007
(E-Mail Removed) wrote On 02/05/07 12:42,:
> I am currently writing a java application that backs up a directory
> and copies it to another location. I want the user to enter the path
> of the directory in a JTextField. For example C:\Documents and
> Settings. Once the user has entered the path they want to backup they
> then click a button which will then check to make sure that, that
> directory exists. If it doesn't a message is displayed and if it does
> then it performs a certain task. How would I go about checking to make
> sure the folder exists.


File theDir = new File(thePath);
if (theDir.exists()) ...

However, I'd encourage you to use a JFileChooser
instead of making the user type the path. If you were
in the user's position, would you rather click on a
couple of folder icons or type

C:\Documents and Settings\Christopher\My Documants\Financial
Records\Mortgage Payments

.... and then curse at the error message?

--
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
Finding out if a HTML page in a foreign domain exists before youallow navigation to it Stevo Javascript 6 02-24-2008 01:45 PM
Template-Meta: Finding out whether a template-definition exists Hendrik Schober C++ 16 09-04-2007 11:48 AM
finding if file exists or not in apache webdav server and if exists what is the mime type of it.... Totan Java 0 04-17-2006 05:13 AM
Finding if a certain form elements exists... Stu ASP .Net 4 08-19-2003 01:10 PM



Advertisments