Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:15:20+00:00 2026-05-28T16:15:20+00:00

i have this working code to delete files and folders from s3. how would

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:15:22+00:00Added an answer on May 28, 2026 at 4:15 pm

    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 is PCRE_ALL, which is "/.*/i"), e.g.:

    $s3 = new AmazonS3();
    $response = $s3->delete_all_objects($bucket, "#myDirectory/.*#");
    

    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:

    Amazon S3’s new Multi-Object Delete gives you the ability to
    delete up to 1000 objects from an S3 bucket with a single request.

    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”:

    The AmazonS3 class now allows you to delete multiple Amazon S3 objects
    using a single HTTP request. This has been exposed as the
    delete_objects() method, and the delete_all_objects() and
    delete_all_object_versions() methods have been rewritten to leverage this new Amazon S3 feature.

    An example for a dedicated multi-object delete (i.e. without wildcards) is shown as well:

    $s3 = new AmazonS3();
    $response = $s3->delete_objects($bucket, array(
        'objects' => array(
            array('Key' => 'file1.txt'),
            array('Key' => 'file2.txt'),
        )
    ));
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a beginner in Ocaml, I have this current working code: ... let ch_in
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
I have this legacy code that I am working with and there is code
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I have this piece of code (summarized)... AnsiString working(AnsiString format,...) { va_list argptr; AnsiString
Any way I can get this working? I have a block of code: <p><a
Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
i have tried this code to redirect a php page.but it s not working
Ok, I have code that is working (posted after this) but before I expand
I have this code I been working on but I'm having a hard time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.