Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.8k views
in .NET FTP by (180 points)
It would be nice if there was DirectoryExists method or if you could check for existance of a Directroy in some way without having to trap an exception.

Exception Trapping is expensive and shouldn't be part of normal processing. The ChangeDirectory returns a boolean but if the directory doesn't exist, it throws an error instead of returning false. Under what conditions does it return false?

I have looked for this and the responses thus far have been to trap for an error. I just want to comment that I don't think that is an acceptable way of detecting for existance.

2 Answers

0 votes
by (162k points)
You're right that we need to add a method for this. It is a bit nasty having to catch an FTPException to find out if it exists by changing into it. Not exactly elegant programming.

Note that in this case there's not really a performance hit in throwing/catching the exception - at least not compared to the cost of contacting the server during the operation.

You can also use GetFileInfos to get the list of files and directories and check thru this list. However this is actually far more expensive than trying to change into the directory.

Anyway, expect a DirectoryExists (or similar) operation soon - we do need it.
0 votes
by (180 points)
I am still wondering about the boolean return value for the ChangeWorkingDirectory method. Does it ever return false?

I have seen some models where you can send a parameter indicating if you want to throw an error if a particular event happens or if you want the result to be false, this may be a good place for it in your API

Categories

...