Skip to main content
This tutorial shows you how to build a recursive upload script that combines , , and to handle duplicate files, duplicate folders, and large files automatically.
The code samples in this tutorial use the .

Prerequisites

  • A Box application with the scope (root_readwrite) enabled
  • Python 3.8 or later installed on your computer
  • The Box Python SDK installed (pip install "boxsdk~=10")
  • An authenticated
  • Completion of the tutorial, which defines the file_upload and file_upload_chunked helper functions this tutorial reuses to avoid duplicating upload logic

Handle duplicate folders

Before you access a subfolder, check whether it already exists in Box. If a folder with the same name exists, use the existing folder instead of creating a new one:
Python v10

Recursively upload a folder

Combine the helper functions into a single recursive function that walks the local directory tree. For each item, the function:
  1. Creates the folder in Box, or retrieves the existing folder, and then recurses into it.
  2. Checks the file size to choose a direct or chunked upload. Files that are 20 MB or larger use chunked upload; smaller files use direct upload.
  3. Uploads a new version when a file with the same name already exists, by using the helpers from the upload methods tutorial.
Python v10
The min_chunked_size parameter defaults to 20 MB, which is the minimum size for . You can increase this threshold, but you cannot decrease it.

Complete example

The following script authenticates a Box client, creates a destination folder (or reuses an existing one), and recursively uploads the contents of a local directory. It reuses the create_box_folder helper to get or create the destination folder in the root folder ("0"):
Python v10

Resources

Last modified on June 10, 2026