Skip to content

Instantly share code, notes, and snippets.

Last active November 6, 2022 23:44
What would you like to do?
Ignore node_modules/bower_components folders in your Dropbox

This script scans your Dropbox (or any given folder) for folders stored in the ignore array and excludes them from syncing. Makes use of the official Dropbox CLI

I'm a beginner at bash, so all improvements are welcome!


set -e

# ========
# Location of your Dropbox folder
# Location of (
# Array of folders to ignore

# =========
function dropbox_install(){
    while true; do
        read -p $'\nDo you want to use download and install (y/n) ' yn
        case $yn in
            [Yy]* )
                dropbox_script_parent=$(dirname $dropbox_script)
                mkdir -p $dropbox_script_parent
                wget -O $dropbox_script ""
                chmod +x $dropbox_script
                recurse $dropbox
            [Nn]* )
                echo 'Aborted. See for manual instructions.';
                exit 1;;

function recurse() {
 for i in "$1"/*;do
    if [ -d "$i" ];then
        j=$(basename "$i")
        if [[ " ${ignore_list[*]} " == *$j* ]]; then
            $dropbox_script exclude "$i"
        recurse "$i"

# ======
# Check Dropbox folder location
if [ -d "$dropbox_folder" ];then
    echo "Dropbox found at $dropbox_folder"
    echo "Dropbox not found"
    exit 1

# Check for
if [ -e "$dropbox_script" ];then
    recurse $dropbox
Copy link

In my dev returning this:

/home/adson/bin/ UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif len(args) == 1 and args[0] == u"list":
ignores/excludes a directory from syncing
dropbox exclude [list]
dropbox exclude add [DIRECTORY] [DIRECTORY] ...
dropbox exclude remove [DIRECTORY] [DIRECTORY] ...

"list" prints a list of directories currently excluded from syncing.
"add" adds one or more directories to the exclusion list, then resynchronizes Dropbox.
"remove" removes one or more directories from the exclusion list, then resynchronizes Dropbox.
With no arguments, executes "list".
Any specified path must be within Dropbox.

Copy link

vvo commented Jun 6, 2015

I have a one liner for you @idleberg.

find `pwd` -type d -regex ".*\(node_modules\|temp\|tmp\|bower_components\|cache\)$" -prune -exec dropbox-cli exclude add {} \;


Copy link

@vvo, this line overwriting the @idleberg script? How use?

Copy link

@vvo Is your script a complete replacement for @idleberg's?

Copy link

backspaces commented May 3, 2016

What's the current state of affairs here? Is the one-liner a solution? If so, how? And is this linux-only? I've heard so but I bet it works on OSX too, also unix based.

Otherwise, is there a script that does work?

Or is DBox just not useful in certain use cases? For me, its mainly my src files which include node_modules. I'd prefer to not have dropbox sync node_modules.

Copy link

add "add" to the recursive function to work

function recurse() { for i in "$1"/*;do if [ -d "$i" ];then j=$(basename "$i") if [[ " ${ignore_list[*]} " == *$j* ]]; then $dropbox_script exclude add "$i" fi recurse "$i" fi done }

Copy link

arshaw commented Aug 26, 2019

this is also possible using rsync. it's rather robust. i wrote a guide here:

Copy link

haoadoreorange commented Jul 4, 2020

this is also possible using rsync. it's rather robust. i wrote a guide here:

@arshaw The thing is, when using rsync you can't have 2 ways sync, so I don't see a point here. Why do I want to constantly sync my folder to Dropbox if then changes in Dropbox not reflected back to project folder. Of course you can manually do it but then its not convient, might just use git it that case.

Copy link

idleberg commented Nov 6, 2022

It's 2022, and I'm now using Maestral (@samschott/maestral)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment