Check if an S3 path exists. Determines whether a bucket, object, or prefix exists in S3. Uses caching and efficient head operations to minimize API calls. Args: path: S3 path to check (e.g., "s3://bucket" or "s3://bucket/key"). **kwargs: Additional a
(self, path: str, **kwargs)
| 710 | return [f.name for f in files] |
| 711 | |
| 712 | def exists(self, path: str, **kwargs) -> bool: |
| 713 | """Check if an S3 path exists. |
| 714 | |
| 715 | Determines whether a bucket, object, or prefix exists in S3. |
| 716 | Uses caching and efficient head operations to minimize API calls. |
| 717 | |
| 718 | Args: |
| 719 | path: S3 path to check (e.g., "s3://bucket" or "s3://bucket/key"). |
| 720 | **kwargs: Additional arguments (unused). |
| 721 | |
| 722 | Returns: |
| 723 | True if the path exists, False otherwise. |
| 724 | |
| 725 | Example: |
| 726 | >>> fs = S3FileSystem() |
| 727 | >>> fs.exists("s3://my-bucket/file.txt") |
| 728 | >>> fs.exists("s3://my-bucket/") |
| 729 | """ |
| 730 | path = self._strip_protocol(path) |
| 731 | if path in ["", "/"]: |
| 732 | # The root always exists. |
| 733 | return True |
| 734 | bucket, key, _ = self.parse_path(path) |
| 735 | if key: |
| 736 | try: |
| 737 | if self._ls_from_cache(path): |
| 738 | return True |
| 739 | info = self.info(path) |
| 740 | return bool(info) |
| 741 | except FileNotFoundError: |
| 742 | return False |
| 743 | elif self.dircache.get(bucket, False): |
| 744 | return True |
| 745 | else: |
| 746 | try: |
| 747 | if self._ls_from_cache(bucket): |
| 748 | return True |
| 749 | except FileNotFoundError: |
| 750 | pass |
| 751 | file = self._head_bucket(bucket) |
| 752 | return bool(file) |
| 753 | |
| 754 | def rm_file(self, path: str, **kwargs) -> None: |
| 755 | bucket, key, version_id = self.parse_path(path) |