Example: Refresh an odrive folder path recursively

Most traditional cloud storage sources have efficient API methods to see if there have been any changes, but other sources (e.g. servers you are connecting using standard protocols such as SFTP, FTP, WebDAV) require that you walk the folder tree and get a listing at each level. These sources are recursively refreshed to look for remote changes less frequently (though if you navigate there using Finder/Windows Explorer, you would see changes in the folders you go into). However, you may want to run the refresh automatically without navigating there on your desktop client on a more frequent basis to meet your particular use case.

Use this simple script for the odrive CLI to do the following:

  1. Refresh a particular odrive folder path, even an entire top-level storage link folder.
  2. Note that this will not expand any placeholder cloud folders, so you can control how resource-intensive your script run will be by scoping down your set of expanded folders (keeping folders you don't care about as placeholder cloud files).

You can also schedule this script to run on a periodic basis, so that you can refresh automatically according to your own schedule.

Be sure to change the $REFRESHPATH value to the path you want to use. For example, if you wanted to refresh the top-level storage folder "SFTP", you could set in your Powershell script:

# Powershell Script to refresh a folder (recursively) in a storage link


# Check Prerequisites
if(!(Test-Path -Path $SYNCBIN)) {
    echo "Downloading CLI binary ... "
    (New-Object System.Net.WebClient).DownloadFile("https://dl.odrive.com/odrivecli-win", "$O\oc.zip")
    $shl=new-object -com shell.application
    del "$O\oc.zip"
    echo "Done!"
if (-Not ($REFRESHPATH) -or !(Test-Path -Path $REFRESHPATH)){
   echo "Missing or Invalid Source Path." 

function RefreshFolders($Path = $REFRESHPATH)
    # Refresh folder
    echo ">>>>>>>>>>> Refreshing $Path"
    ."$SYNCBIN" "refresh" "$Path"

    # Recurse through any subfolders
    foreach ($ITEM in Get-ChildItem $Path | where {($_.psiscontainer)} )
        if (Test-Path $ITEM.FullName -PathType Container)
            RefreshFolders $ITEM.FullName

RefreshFolders -Path "$REFRESHPATH"

echo "Done."

Learn how to configure your computer to run the script automatically.