[RESOLVED] Best way to check whether a file is file or directory when using FTP
I have to loop through a list of directories to look for a file, but I cannot use the filesystem functions because the list is retrieved from an FTP connection and a priori I wouldn't have to know the real path to the file. So, I use ftp_nlist to retrieve an array with all the directories within a relative path, but I only want to do something with the subdirectories: to check whether a file exists within any of them (just one level deep needed), and discard the files and current or parent directories.
As far as I know I cannot use functions like is_dir nor is_file nor file_exists because I can't get the real path (both absolute and relative) to them. I thought on using ftp_size but I'm not sure if it's ok and if there's a better way.
Alternatively you could use ftp_rawlist() instead, and parse the the beginning of each entry where it lists the file type and permissions info.
I won't guarantee, however, that you'll get the same results from different target hosts.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks