Re: How can i check whether a file exists? - WeOnlyDo Discussion board

Re: How can i check whether a file exists? (General questions)

by david.pearson@gmsl.co.uk, Monday, March 19, 2012, 15:55 (4429 days ago) @ wodDamir

David,

You didn't mention that you're using Blocking mode in your initial post, so I assumed you were using asynchronous mode.

However, this works perfectly:
[code]
String fullRemotePath = /path/to/file/to/check ;
Ftp1.Rename(fullRemotePath , fullRemotePath );
[/code]

If file doesn't exist, an exception will be thrown immediately, and if it does, it will remain same sa it was, unchanged.

Please note that there is no command in FTP that does this. The above is only a workaround on how to achieve something that isn't implemented into the protocol itself.

As for CheckDir method, you can find help on it here.

Regards,
Damba

Many thanks. My solution is to use an attributes delegate method, and store the results of that in a variable. My code calls GetAttributes and checks the contents of the variable to compare the name of the file to determine whether it exists.

I'm not sure i like idea of renaming a file (i understand what you're proposing though).


Complete thread: