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:
$REFRESHPATH=C:\Users\mywindowsuser\odrive\SFTP\

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

$O="$HOME\.odrive\common"
$SYNCBIN="$O\odrive.exe"
$REFRESHPATH="C:\Users\WINDOWS_USER_NAME\odrive\SOURCE_LINK_NAME\SOURCE_LINK_PATH"

# 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
    $shl.namespace("$O").copyhere($shl.namespace("$O\oc.zip").items(),0x10)
    del "$O\oc.zip"
    echo "Done!"
}
if (-Not ($REFRESHPATH) -or !(Test-Path -Path $REFRESHPATH)){
   echo "Missing or Invalid Source Path." 
   break
}

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."
TBD
TBD

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