i have this working code to delete files and folders from s3.
how would you delete using wildcard * ?
$s3 = new AmazonS3();
$bucket = 'mybucket';
$folder = 'myDirectory/*';// this doesnt work
$response = $s3->get_object_list($bucket, array(
'prefix' => $folder
));
foreach ($response as $v) {
$s3->delete_object($bucket, $v);
}
Presumably using wildcard * means you want to delete all objects at once rather than one at a time?
This is possible via delete_all_objects($bucket, $pcre), where
$pcreis an optional Perl-Compatible Regular Expression (PCRE) to filter the names against (default isPCRE_ALL, which is"/.*/i"), e.g.:I’ve chosen
#rather than the usual/as the pattern enclosing delimiter to avoid escaping (not a problem with the single slash here, but it get’s messy soon for more complex cases), see Delimiters for details.Implementation Note
Please note that deleting multiple objects had not been possible in the past at the Amazon S3 API level and simulated in the AWS SDK for PHP with a for loop within
delete_all_objects()as well, i.e. it used one request per object still; fortunately, Amazon has finally introduced Amazon S3 – Multi-Object Delete in December 2011:Support for S3 Multi Object Delete has been added to the AWS SDK for PHP shortly thereafter accordingly, see AWS SDK for PHP 1.4.8 “Zanarkand”:
An example for a dedicated multi-object delete (i.e. without wildcards) is shown as well: