Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative "../storage_control_list_folders"
require_relative "../storage_control_rename_folder"
require_relative "../storage_control_delete_folder"
require_relative "../delete_folder_recursive"

describe "Storage Control Folders" do
let(:bucket_name) { random_bucket_name }
Expand Down Expand Up @@ -65,4 +66,21 @@
delete_folder bucket_name: bucket_name, folder_name: new_folder_name
end
end

it "delete_folder_recursive" do
recursive_folder_name = "#{folder_name}_recursive"
# create_folder
out, _err = capture_io do
create_folder bucket_name: bucket_name, folder_name: recursive_folder_name
end
assert_includes out, recursive_folder_name

# delete_folder_recursive
storage_control = Google::Cloud::Storage::Control.storage_control
folder_path = storage_control.folder_path project: "_", bucket: bucket_name, folder: recursive_folder_name

assert_output "Deleted folder: #{folder_path}\n" do
delete_folder_recursive bucket_name: bucket_name, folder_name: recursive_folder_name
end
end
end
40 changes: 40 additions & 0 deletions google-cloud-storage-control/samples/delete_folder_recursive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START storage_control_delete_folder_recursive]
def delete_folder_recursive bucket_name:, folder_name:
# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
#
# Name of the folder you want to delete
# folder_name = "name-of-the-folder"

require "google/cloud/storage/control"

storage_control = Google::Cloud::Storage::Control.storage_control

# Set project to "_" to signify globally scoped bucket
folder_path = storage_control.folder_path project: "_", bucket: bucket_name, folder: folder_name

request = Google::Cloud::Storage::Control::V2::DeleteFolderRecursiveRequest.new name: folder_path

operation = storage_control.delete_folder_recursive request

operation.wait_until_done!

puts "Deleted folder: #{folder_path}"
end
# [END storage_control_delete_folder_recursive]

delete_folder_recursive bucket_name: ARGV.shift, folder_name: ARGV.shift if $PROGRAM_NAME == __FILE__
Loading