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
Download the Backblaze B2 command line tool
Open a PowerShell prompt
mkdir Empty
cd Empty
& '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
& '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& '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
Repeat step 7 until you reach the directory you want to delete
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