开发者

How to separate files from folders?

开发者 https://www.devze.com 2022-12-15 23:50 出处:网络
I have a simple problem. My (Delphi 2007 with Indy 9) application connects to an FTP server to retrieve开发者_StackOverflow社区 a list of files. (NLST, not LIST) I then download every file separately

I have a simple problem. My (Delphi 2007 with Indy 9) application connects to an FTP server to retrieve开发者_StackOverflow社区 a list of files. (NLST, not LIST) I then download every file separately for further processing.

Unfortunately, the administrators of the FTP site added a subfolder in the folder where the files are located. The current code thinks it's a file, thus it tries to download it. This fails, of course. Right now, I just solved it by checking if the process succeeded or not and if not, it will add a message to the error log but it also continues processing other files.

But what I would like to do is add some code which will check first if the name in the filelist is a filename or foldername. What's the easiest way to do this?

Note: I cannot rely on the LIST method to return a file list with additional attributes since I'm connecting to multiple FTP servers which could all define their own file format. Besides, parsing such a list isn't a very easy task, even if I could determine which kind of list the FTP server returns. To make matters worse, some of the filenames are just numbers with no extension so wildcards don't help either.


The NLST command does not deliver any details about the names it provides, by design. You must use the LIST or MLSD/MLST command to get details so you can differentiate between different item types. Yes, when using LIST, there are many many different formats used online and you would have to detect and decode them manually as needed (for instance, the TIdFTP component in Indy 10 has several dozen parsers inplemented for exactly that purpose). That is why the MLST/MLST extension was invented. It is specifically designed to have a unified format that is easily parsed in code without any guesswork. Many modern FTP servers support that extension.

0

精彩评论

暂无评论...
验证码 换一张
取 消