Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for directories

 
Peter Phung
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Phung
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic