Delete a directory in Backblaze B2

Delete all of the files within a directory, including sub-directories, in Backblaze B2.

Files in Backblaze B2 are not stored hierarchically. Their path is simply part of their filename. Therefore deleting a directory is really a matter of deleting all files that have a filename that starts with the directoryā€™s path.

Instructions

  1. Download the Backblaze B2 command line tool

  2. Open a PowerShell prompt

  3. mkdir Empty

  4. cd Empty

  5. & 'C:\<PATH_TO_B2>\b2' authorize-account <Key ID> <Application Key>

    Ex: & 'C:\Program Files\Backblaze B2\b2' authorize-account 0000000000000000000000000 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

    Output: Using https://api.backblazeb2.com

  6. & 'C:\<PATH_TO_B2>\b2' ls <BUCKETNAME>

    Ex: & 'C:\Program Files\Backblaze B2\b2' ls MYBUCKET

    Output: All of the directories directly within the bucket

  7. & 'C:\<PATH_TO_B2>\b2' ls <BUCKETNAME> <DIRECTORY_NAME>

    Ex: & 'C:\Program Files\Backblaze B2\b2' ls MYDIRECTORY

    Output: All of the directories directly within the directory

  8. Repeat step 7 until you reach the directory you want to delete

  9. b2 sync --allowEmptySource --delete . b2://<BUCKETNAME>/<A>/<PATH>/<PREFIX>

    Ex: & 'C:\Program Files\Backblaze B2\b2' sync --allowEmptySource --delete . b2://MYBUCKET/DIRA/DIRB/DIRC/DIRD

Ā 

For a large number of files this can take a long time to run.

Related articles

Ā© 2023 Foray, LLC - All Rights Reserved