-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wildcards give strange results when listing directories #582
Comments
Flysystem is not designed to handle wildcard searches. So the error here is that the |
Are wildcard searches something that could be supported, or is normalising that across the various providers impractical? If so, then I guess I could extend the FTP driver to handle wildcards separately from the directory. In my current project I have to sift through some very large directories to find unprocessed files, and not pulling the file details I don't need down to the application would help to speed things up and keep data transfers and memory usage down. |
@judgej normalising it across the different adapters is virtually impossible in the current listContents contract without bloating it. For instance, some adapters would have to polyfil the behaviour heavily. I'd rather introduce a |
In case it is useful to others: // The Flysystem Filesystem object.
protected $filesystem;
/**
* Scan for files matching a given RE at a given path.
* Returns a Flysystem normalised array.
*/
protected function scanFiles($path, $match = null)
{
// There is no reliable wildcard matching at this level, so get a listing
// of all files in the directory.
$contents = $this->filesystem->listContents($path);
// Filter out files that don't match the RE.
if ( ! empty($match)) {
$contents = array_filter($contents, function ($file) use ($match) {
return preg_match($match, $file['basename']);
});
}
return $contents;
} Further checks could be added to filter out directories, check if the path really is a directory and not a file, and that it exists etc. but it's a start. Could be extended to wildcards in directories too, with a recursive Usage is something like this: $files = $this->scanFiles('/uploads', '/.+_ACK\.xml$/'); |
@judgej that's what I do. I almost always try solve this through structure. It seems that all the |
Yep - I'm connecting to a third-party API, which consists of an FTP account and file structure I can't change. At the very least, I might try to get them to enable SFTP, and Flysystem will make switching to that a cinch :-) |
Wildcards kind of work, but kind of don't.
Files have the form
NNNN_ACK.xml
so I'm using the wildcardOutgoing/*_ACK.xml
to fined them.I get results like this:
The problem is the extra
/*_ACK.xml
in the returned path of the file. The remote OS won't be adding this in, so I guess Flysystem is making an assumption that there are no wildcards, and what has been provided is an exact directory.Similarly the dirname entry should be
Outgoing
and notOutgoing/*_ACK.xml
The text was updated successfully, but these errors were encountered: