aspose file tools*
The moose likes Java in General and the fly likes Checking for directories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Checking for directories" Watch "Checking for directories" New topic
Author

Checking for directories

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
I'm trying to check for directories on a FTP server before uploading files.
I've tried using :
File f = new File("ftp://hostname/dir/dir/");
if (f.exists()) {
.....
} else {
.....
}
but the application always uses the else statement when i know that the directory exists.
Am i specifying the directory path incorrectly or am i using the wrong method?
Pete


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Peter
exists() just returns true 'if and only if the file ... exists'. what you want to use is the isDirectory() method which returns true if the given path is a directory and if it exists.


Dave
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Dave,
i've tried isDirectory() as well as exists() i.e.
File f = new File("ftp://hostname/dir/dir/");
if (f.isDirectory()) {
.....
} else {
.....
}
this didn't work for me yet. have i defined the pathname wrong?
Pete
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Peter
I am not an expert yet with network comm butI am working in it, with that said...
I don't think you need to specify the protocol to create the File object, all you should need is the path.
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Can you tell me if i'm using the right code then
boolean connect() {
fileStruct();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
String user = tfUserName.getText();
taDisplay.appendText("Connecting to host "+vn);
client = new FtpClient(vn);
client.login(user, pw);
taDisplay.appendText("\nUser "+user+" login OK");
File example = new File("birmha19/./peterTest/509/VV00A00A/");
if (example.isDirectory()) {
taDisplay.appendText("\nThe directory exists");
}
}
catch (Exception e) {
taDisplay.appendText("\nError1 : "+e.toString());
return false;
}
return true;
}
this is the method i've been using. it's not all there but i got th e important bits. it's compiling but it dosn't run as expected. The directory exists on the server but the application just dosn't find it. what can i do?
 
Consider Paul's rocket mass heater.
 
subject: Checking for directories