b2sdk._internal.scan.folder

class b2sdk._internal.scan.folder.AbstractFolder[source]

Bases: object

Interface to a folder full of files, which might be a B2 bucket, a virtual folder in a B2 bucket, or a directory on a local file system.

Files in B2 may have multiple versions, while files in local folders have just one.

abstract all_files(reporter, policies_manager=<b2sdk._internal.scan.policies.ScanPoliciesManager object>)[source]

Return an iterator over all of the files in the folder, in the order that B2 uses.

It also performs filtering using policies manager.

No matter what the folder separator on the local file system is, “/” is used in the returned file names.

If a file is found, but does not exist (for example due to a broken symlink or a race), reporter will be informed about each such problem.

Parameters:
  • reporter (Optional[ProgressReport]) – a place to report errors

  • policies_manager – a policies manager object

Return type:

Iterator[AbstractPath]

abstract folder_type()[source]

Return one of: ‘b2’, ‘local’.

Return type:

str

abstract make_full_path(file_name)[source]

Return the full path to the file.

Parameters:

file_name (str) – a file name

Return type:

str

b2sdk._internal.scan.folder.join_b2_path(relative_dir_path, file_name)[source]

Like os.path.join, but for B2 file names where the root directory is called ‘’.

Parameters:
  • relative_dir_path (str | Path) –

  • file_name (str) –

class b2sdk._internal.scan.folder.LocalFolder(root)[source]

Bases: AbstractFolder

Folder interface to a directory on the local machine.

Parameters:

root (str | Path) –

__init__(root)[source]

Initialize a new folder.

Parameters:

root (str | Path) – path to the root of the local folder. Must be unicode.

folder_type()[source]

Return folder type.

Return type:

str

all_files(reporter, policies_manager=<b2sdk._internal.scan.policies.ScanPoliciesManager object>)[source]

Yield all files.

Parameters:
  • reporter (Optional[ProgressReport]) – a place to report errors

  • policies_manager – a policy manager object, default is DEFAULT_SCAN_MANAGER

Return type:

Iterator[LocalPath]

make_full_path(file_name)[source]

Convert a file name into an absolute path, ensure it is not outside self.root

Parameters:

file_name (str) – a file name

ensure_present()[source]

Make sure that the directory exists.

ensure_non_empty()[source]

Make sure that the directory exists and is non-empty.

b2sdk._internal.scan.folder.b2_parent_dir(file_name)[source]
class b2sdk._internal.scan.folder.B2Folder(bucket_name, folder_name, api)[source]

Bases: AbstractFolder

Folder interface to b2.

__init__(bucket_name, folder_name, api)[source]
Parameters:
  • bucket_name (str) – a name of the bucket

  • folder_name (str) – a folder name

  • api (b2sdk._internal.api.B2Api) – an API object

all_files(reporter, policies_manager=<b2sdk._internal.scan.policies.ScanPoliciesManager object>)[source]

Yield all files.

Parameters:
Return type:

Iterator[B2Path]

get_file_versions()[source]
folder_type()[source]

Return folder type.

Return type:

str

make_full_path(file_name)[source]

Make an absolute path from a file name.

Parameters:

file_name (str) – a file name