No project description provided
Project description
This document explains the usage of the Python function files_in_bucket, which can be used to list files within a specific folder in a Google Cloud Storage bucket.
Parameters:
-
bucket_name (str): The name of the Google Cloud Storage bucket.
-
folder_name (str): The name of the folder within the bucket to list files from.
-
filename_needed (bool, optional): Defaults to True. If True, returns a list of filenames.
-
file_object_needed (bool, optional): Defaults to False. If True, returns a list of file objects.
-
list_sub_folders (bool, optional): Defaults to False. If True, includes files from subfolders within the specified folder.
Return Value:
- A list of filenames (strings) if filename_needed is True.
- A list of file objects, which can further be used to extract different aspects of the contained file, if file_object_needed is True.
- None if both filename_needed and file_object_needed are False.
- Raises an exception if an error occurs.
Example Usage:
Python:
from google.cloud import storage
bucket_name = "my-bucket" folder_name = "data/"
Get filenames only
filenames = files_in_bucket(bucket_name, folder_name) print(filenames)
Get file objects only
file_objects = files_in_bucket(bucket_name, folder_name, file_object_needed=True) for blob in file_objects: print(blob.name)
Include files from subfolders
all_files = files_in_bucket(bucket_name, folder_name, list_sub_folders=True) print(all_files)
Additional Notes:
- This function requires the google-cloud-storage library to be installed.
- Ensure you have proper authentication set up to access the specified bucket.
- The function includes basic error handling, but you may want to implement more specific handling based on your needs.
- I hope this README provides a clear explanation of the files_in_bucket function and its usage. Feel free to ask if you have any further questions. Email - preyaa.atri91@gmail.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file GCS_bucket_files_or_filenames-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: GCS_bucket_files_or_filenames-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 182a95fb4b411f6017934757d17386f1b0ed2a9510a30d18fee0edcc71f85409 |
|
MD5 | 46f584fa9d64681377a0b508e9d21128 |
|
BLAKE2b-256 | 61b43dc14d6a10b9e5d8059fccf40c35277c6092617a55c6c0ee6bfe9dda46d4 |